Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than shell32, prefix the name with the module name and a period.
<DllImport("SHELL32", CallingConvention:=CallingConvention.StdCall)> _
Shared Function SHAppBarMessage(ByVal dwMessage As Integer, ByRef pData As APPBARDATA) As Integer
End Function
#Region " Class Variablen"
Private DockSize As Size
Private MyDockForm As System.Windows.Forms.Form
Private fBarRegistered As Boolean = False
Private MyEdge As ABEdge
Friend uCallBack As Integer
Dim PosfixTimer As New System.Timers.Timer
#End Region
#Region " Structure und Enum"
<StructLayout(LayoutKind.Sequential)> _
Public Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure
<StructLayout(LayoutKind.Sequential)> _
Structure APPBARDATA
Public cbSize As Integer
Public hWnd As IntPtr
Public uCallbackMessage As Integer
Public uEdge As Integer
Public rc As RECT
Public lParam As Boolean
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure TaskbarState
Public T_EDGE As ABEdge
Public T_STATE As ABState
Public T_SIZE As RECT
End Structure
Public Enum AppBarDockStyle As Integer
None
ScreenLeft
ScreenTop
ScreenRight
ScreenBottom
End Enum
#End Region
#Region " DLLImports"
<DllImport("SHELL32", CallingConvention:=CallingConvention.StdCall)> _
Shared Function SHAppBarMessage(ByVal dwMessage As Integer, ByRef pData As APPBARDATA) As Integer
End Function
<DllImport("user32.dll")> _
Shared Function GetSystemMetrics(ByVal Index As Integer) As Integer
End Function
<DllImport("user32.dll", ExactSpelling:=True)> _
Function LockWorkStation() As Boolean
End Function
<DllImport("User32.dll", ExactSpelling:=True, CharSet:=System.Runtime.InteropServices.CharSet.Auto)> _
Private Shared Function MoveWindow(ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer,
ByVal repaint As Boolean) As Boolean
End Function
<DllImport("User32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function RegisterWindowMessage(ByVal msg As String) As Integer
End Function
Private Declare Auto Function FindWindow Lib "user32" ( ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
#End Region
#Region " Propertys"
Public ReadOnly Property IsBarRegistered() As Boolean
Get
Return fBarRegistered
End Get
End Property
Public Property AppBarDockSize() As Size
Get
Return DockSize
End Get
Set(ByVal Value As Size)
DockSize = Value
End Set
End Property
Private Property AppBarEdge() As ABEdge
Get
Return MyEdge
End Get
Set(ByVal Value As ABEdge)
MyEdge = Value
End Set
End Property
#End Region
'Constructor
Friend Sub New(ByRef DockForm As System.Windows.Forms.Form, ByVal dockStyle As AppBarDockStyle, ByVal AppBarSize As Size)
'Pos Form
Public Sub UpdateDockedAppBarPosition(ByVal dockStyle As AppBarDockStyle)
Select Case dockStyle
Case AppBarDockStyle.None : Return
Case AppBarDockStyle.ScreenLeft : AppBarEdge = ABEdge.ABE_LEFT
Case AppBarDockStyle.ScreenTop : AppBarEdge = ABEdge.ABE_TOP
Case AppBarDockStyle.ScreenRight : AppBarEdge = ABEdge.ABE_RIGHT
Case AppBarDockStyle.ScreenBottom : AppBarEdge = ABEdge.ABE_BOTTOM
Case Else : AppBarEdge = ABEdge.ABE_TOP
End Select
End Sub
'Register (ABSetPos)
Friend Sub RegisterBar(ByVal hWnd As IntPtr, ByRef uCallbackMessage As Int32, ByVal idealSize As Size, ByVal DockEdge As ABEdge)
Dim abd As APPBARDATA = New APPBARDATA
uCallbackMessage = RegisterWindowMessage("AppBarMessage")
abd.uCallbackMessage = uCallbackMessage
Dim ret As Long = SHAppBarMessage(CType(ABMsg.ABM_NEW, Integer), abd)
fBarRegistered = True
ABSetPos(hWnd, idealSize, DockEdge)
End Sub
'UnregAppBar
Friend Sub UnregisterAppBar(ByVal hWnd As IntPtr)
Dim abd As APPBARDATA = New APPBARDATA
abd.cbSize = Marshal.SizeOf(abd)
abd.hWnd = hWnd
SHAppBarMessage(ABMsg.ABM_REMOVE, abd)
End Sub
'Reg Form as Appbar
Friend Sub ABSetPos(ByVal hWnd As IntPtr, ByVal idealSize As Size, ByVal DockEdge As ABEdge)
Dim abd As APPBARDATA = New APPBARDATA
abd.cbSize = Marshal.SizeOf(abd)
abd.hWnd = hWnd
abd.uEdge = CType(ABEdge.ABE_TOP, Integer)
abd.uEdge = CType(DockEdge, Integer)
If abd.uEdge = CType(ABEdge.ABE_LEFT, Integer) OrElse abd.uEdge = CType(ABEdge.ABE_RIGHT, Integer) Then
abd.rc.top = 0
abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height
If abd.uEdge = CType(ABEdge.ABE_LEFT, Integer) Then
abd.rc.left = 0
abd.rc.right = idealSize.Width
Else
abd.rc.right = SystemInformation.PrimaryMonitorSize.Width
abd.rc.left = abd.rc.right - idealSize.Width
End If
Else
abd.rc.left = 0
abd.rc.right = SystemInformation.PrimaryMonitorSize.Width
If abd.uEdge = CType(ABEdge.ABE_TOP, Integer) Then
abd.rc.top = 0
abd.rc.bottom = idealSize.Height
Else
abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height
abd.rc.top = abd.rc.bottom - idealSize.Height
End If
End If
SHAppBarMessage(CType(ABMsg.ABM_QUERYPOS, Integer), abd)
Select Case abd.uEdge
Case CType(ABEdge.ABE_LEFT, Integer)
abd.rc.right = abd.rc.left + idealSize.Width
' break
Case CType(ABEdge.ABE_RIGHT, Integer)
abd.rc.left = abd.rc.right - idealSize.Width
' break
Case CType(ABEdge.ABE_TOP, Integer)
abd.rc.bottom = abd.rc.top + idealSize.Height
' break
Case CType(ABEdge.ABE_BOTTOM, Integer)
abd.rc.top = abd.rc.bottom - idealSize.Height
' break
End Select
SHAppBarMessage(CType(ABMsg.ABM_SETPOS, Integer), abd)
MoveWindow(abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, True)
End Sub
Public Sub SetAutoHide()
Dim lRet As Long
Dim abd As APPBARDATA = New APPBARDATA
abd.cbSize = Marshal.SizeOf(abd)
abd.uEdge = ABEdge.ABE_RIGHT
'abd.hWnd = FindWindow("Shell_TrayWnd", "") 'Tasbar Handle
abd.hWnd = MyDockForm.Handle
abd.lParam = True
lRet = SHAppBarMessage(ABMsg.ABM_SETAUTOHIDEBAR, abd)
End Sub
Friend Function GetWinTaskbarState(ByRef WinTaskBar As TaskbarState) As Boolean
Dim hWndAppBar As Long
Dim ABD As New APPBARDATA
Dim state As Long, tsize As Long
Dim msg As New StringBuilder
Dim position As Integer
Dim retState As TaskbarState
'get the appbar state
state = SHAppBarMessage(CType(ABMsg.ABM_GETSTATE, Integer), ABD)
Select Case state
Case ABState.ABS_MANUAL
retState.T_STATE = ABState.ABS_MANUAL
Case ABState.ABS_ALWAYSONTOP
retState.T_STATE = ABState.ABS_ALWAYSONTOP
Case ABState.ABS_AUTOHIDE
retState.T_STATE = ABState.ABS_AUTOHIDE
Case ABState.ABS_AUTOHIDEANDONTOP
retState.T_STATE = ABState.ABS_AUTOHIDEANDONTOP
End Select
'see which edge has a taskbar
For position = ABEdge.ABE_LEFT To ABEdge.ABE_BOTTOM
ABD.uEdge = position
hWndAppBar = SHAppBarMessage(CType(ABMsg.ABM_GETAUTOHIDEBAR, Integer), ABD)
If hWndAppBar > 0 Then
Select Case position
Case ABEdge.ABE_LEFT : retState.T_EDGE = ABEdge.ABE_LEFT
Case ABEdge.ABE_TOP : retState.T_EDGE = ABEdge.ABE_TOP
Case ABEdge.ABE_RIGHT : retState.T_EDGE = ABEdge.ABE_RIGHT
Case ABEdge.ABE_BOTTOM : retState.T_EDGE = ABEdge.ABE_BOTTOM
End Select
End If
Next
'Rückgabe ob sich der TaskbarStatus verändert hat
WinTaskBar = retState
Return True
Catch err As Exception
Trace.Assert(False)
Return False
End Try
End Function
'Eventhandler Form Load
Private Overloads Sub OnLoad(ByVal sender As Object, ByVal e As System.EventArgs)
'UpdateDockedAppBarPosition(RegisterAppBar.AppBarDockStyle.ScreenRight)
End Sub
'Eventhandler Form Close
Private Overloads Sub OnClosing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
UnregisterAppBar(MyDockForm.Handle)
End Sub
End Class
Sample Code:
Alternative Managed API:
Do you know one? Please contribute it!
The SHAppBarMessage API. Uses the [APPBARDATA] structure.
6/15/2019 8:41:15 AM - -120.236.174.156
The APPBARDATA Structure for use with the SHAppBarMessage. Also requires the [RECT] structure.
1/22/2009 10:29:55 AM - -67.210.162.2
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).