Как определить расположение панели задач (TaskBar) при помощи
SHAppBarMessage.
Компилятор: Visual Basic 5, 6
При помощи API функции SHAppBarMessage можно определить
местоположение и настройки панели задач для
каждого пользователя. Функция позволяет узнать
такие настройки как автоскрытие и размещение
поверх всех окон, а так же координаты панели
задач.
Итак, разместите следующий код в секции
объявлений BAS модуля:
Option Explicit
Public Const ABM_NEW = &H0
Public Const ABM_REMOVE = &H1
Public Const ABM_QUERYPOS = &H2
Public Const ABM_SETPOS = &H3
Public Const ABM_GETSTATE = &H4
Public Const ABM_GETTASKBARPOS = &H5
Public Const ABM_ACTIVATE = &H6
Public Const ABM_GETAUTOHIDEBAR = &H7
Public Const ABM_SETAUTOHIDEBAR = &H8
Public Const ABM_WINDOWPOSCHANGED = &H9
Public Const ABN_STATECHANGE = &H0
Public Const ABN_POSCHANGED = &H1
Public Const ABN_FULLSCREENAPP = &H2
Public Const ABN_WINDOWARRANGE = &H3
Public Const ABS_AUTOHIDE = &H1
Public Const ABS_ALWAYSONTOP = &H2
Public Const ABE_LEFT = 0
Public Const ABE_TOP = 1
Public Const ABE_RIGHT = 2
Public Const ABE_BOTTOM = 3
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Type APPBARDATA
cbSize As Long
hwnd As Long
uCallbackMessage As Long
uEdge As Long
rc As RECT
lParam As Long 'сообщение
End Type
Declare Function SHAppBarMessage Lib "shell32" _
(ByVal dwMessage As Long, _
pData As APPBARDATA) As Long
Добавьте на форму кнопку (Command1), текстовое поле
(Text1), установите в нём возможность отображать
несколько строчек и скролбары в 2 - Vertical и
добавьте следующий код:
Option Explicit
Private Sub Command1_Click()
Dim rc As RECT
Dim ABD As APPBARDATA
Dim state As Long
Dim position As Integer
Dim hWndAppBar As Long
Dim msg As String
'инициализируем структуру APPBARDATA
ABD.cbSize = Len(ABD)
'get the appbar state
state = SHAppBarMessage(ABM_GETSTATE, ABD)
'подготавливаем соответствующие сообщения в зависимости от результатов
msg = "SHAppBarMessage ABM_GETSTATE return value is " & state & ":" & vbCrLf & vbCrLf
Select Case state
Case False
msg = msg & " - Auto Hide= False, Always on Top = False." & vbCrLf
msg = msg & " - User allows apps cover the taskbar." & vbCrLf
msg = msg & " - The taskbar must be manually invoked with maximized apps."
Case ABS_ALWAYSONTOP
msg = msg & " - Always on Top = True." & vbCrLf
msg = msg & " - User wants the taskbar on-screen at all times." & vbCrLf
msg = msg & " - The available screen is reduced by the taskbar size."
Case Else
msg = msg & " - Auto Hide = True." & vbCrLf
msg = msg & " - The taskbar appears on a mousemove." & vbCrLf
msg = msg & " - There are taskbar(s) positioned on the "
'определяем края панели задач
For position = ABE_LEFT To ABE_BOTTOM
ABD.uEdge = position
hWndAppBar = SHAppBarMessage(ABM_GETAUTOHIDEBAR, ABD)
If hWndAppBar > 0 Then
Select Case position
Case ABE_LEFT: msg = msg & "LEFT "
Case ABE_TOP: msg = msg & "TOP "
Case ABE_RIGHT: msg = msg & "RIGHT "
Case ABE_BOTTOM: msg = msg & "BOTTOM "
End Select
End If
Next
End Select
'показываем результаты
Text1.Text = msg
End Sub
|