171 lines
5.4 KiB
VB.net
171 lines
5.4 KiB
VB.net
Imports System.Runtime.InteropServices
|
|
|
|
Public Class Sidebar2
|
|
<DllImport("SHELL32", CallingConvention:=CallingConvention.StdCall)>
|
|
Private Shared Function SHAppBarMessage(ByVal dwMessage As Integer, ByRef BarrData As AppDeskBar) As Integer
|
|
End Function
|
|
<DllImport("User32.dll", CharSet:=CharSet.Auto)>
|
|
Public Shared Function RegisterWindowMessage(ByVal msg As String) As Integer
|
|
End Function
|
|
|
|
|
|
Structure RECT
|
|
Public left As Integer
|
|
Public top As Integer
|
|
Public right As Integer
|
|
Public bottom As Integer
|
|
End Structure
|
|
|
|
Structure AppDeskBar
|
|
Public cbSize As Integer
|
|
Public hWnd As IntPtr
|
|
Public uCallbackMessage As Integer
|
|
Public uEdge As Integer
|
|
Public rc As RECT
|
|
Public lParam As IntPtr
|
|
End Structure
|
|
|
|
Public Enum ABMsg
|
|
ABM_NEW = 0
|
|
ABM_REMOVE = 1
|
|
ABM_QUERYPOS = 2
|
|
ABM_SETPOS = 3
|
|
ABM_GETSTATE = 4
|
|
ABM_GETTASKBARPOS = 5
|
|
ABM_ACTIVATE = 6
|
|
ABM_GETAUTOHIDEBAR = 7
|
|
ABM_SETAUTOHIDEBAR = 8
|
|
ABM_WINDOWPOSCHANGED = 9
|
|
ABM_SETSTATE = 10
|
|
End Enum
|
|
Public Enum ABEdge
|
|
ABE_LEFT = 0
|
|
ABE_TOP = 1
|
|
ABE_RIGHT = 2
|
|
ABE_BOTTOM = 3
|
|
End Enum
|
|
Public Enum ABNotify
|
|
ABN_STATECHANGE = 0
|
|
ABN_POSCHANGED = 1
|
|
ABN_FULLSCREENAPP = 2
|
|
ABN_WINDOWARRANGE = 3
|
|
End Enum
|
|
|
|
Private AppDeskData As AppDeskBar
|
|
Private fBarRegistered As Boolean = False
|
|
Private Form As Form
|
|
|
|
Public ReadOnly Property SidebarRegistered As Boolean
|
|
Get
|
|
Return fBarRegistered
|
|
End Get
|
|
End Property
|
|
|
|
Public Property uCallBack As Integer
|
|
|
|
Public Sub New(pForm As Form)
|
|
Form = pForm
|
|
End Sub
|
|
|
|
Public Sub RegisterBar(dockEdge As ABEdge)
|
|
AppDeskData = New AppDeskBar()
|
|
AppDeskData.cbSize = Marshal.SizeOf(AppDeskData)
|
|
AppDeskData.hWnd = Form.Handle
|
|
If Not fBarRegistered Then
|
|
fBarRegistered = True
|
|
|
|
Form.FormBorderStyle = FormBorderStyle.None
|
|
Form.ShowInTaskbar = False
|
|
|
|
uCallBack = RegisterWindowMessage("AppBarMessage")
|
|
AppDeskData.uCallbackMessage = uCallBack
|
|
|
|
'ToDo: Unsigned Integers not supported
|
|
SHAppBarMessage(CInt(ABMsg.ABM_NEW), AppDeskData)
|
|
|
|
ABSetPos(dockEdge)
|
|
Else
|
|
SHAppBarMessage(CInt(ABMsg.ABM_REMOVE), AppDeskData)
|
|
fBarRegistered = False
|
|
End If
|
|
End Sub
|
|
|
|
Public Sub UnregisterSidebar()
|
|
If fBarRegistered = True Then
|
|
fBarRegistered = False
|
|
|
|
Form.FormBorderStyle = FormBorderStyle.Sizable
|
|
Form.ShowInTaskbar = True
|
|
|
|
'----NEW
|
|
Dim abd As New AppDeskBar()
|
|
abd.cbSize = Marshal.SizeOf(abd)
|
|
abd.hWnd = Form.Handle
|
|
|
|
' TODO: Save and restore width and taskbar
|
|
'Me.Width = 305
|
|
'Me.Height = 85
|
|
'Me.ShowInTaskbar = True
|
|
SHAppBarMessage(ABMsg.ABM_REMOVE, abd)
|
|
End If
|
|
End Sub
|
|
|
|
Public Sub ABSetPos(dockEdge As ABEdge)
|
|
Dim abd As New AppDeskBar()
|
|
abd.cbSize = Marshal.SizeOf(abd)
|
|
abd.hWnd = Form.Handle
|
|
abd.uEdge = CInt(dockEdge)
|
|
|
|
If abd.uEdge = CInt(ABEdge.ABE_LEFT) Or abd.uEdge = CInt(ABEdge.ABE_RIGHT) Then
|
|
abd.rc.top = 0
|
|
abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height
|
|
If abd.uEdge = CInt(ABEdge.ABE_LEFT) Then
|
|
abd.rc.left = 0
|
|
abd.rc.right = Form.Size.Width
|
|
Else
|
|
abd.rc.right = SystemInformation.PrimaryMonitorSize.Width
|
|
abd.rc.left = abd.rc.right - Form.Size.Width
|
|
End If
|
|
Else
|
|
abd.rc.left = 0
|
|
abd.rc.right = SystemInformation.PrimaryMonitorSize.Width
|
|
If abd.uEdge = CInt(ABEdge.ABE_TOP) Then
|
|
abd.rc.top = 0
|
|
abd.rc.bottom = Form.Size.Height
|
|
Else
|
|
abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height
|
|
abd.rc.top = abd.rc.bottom - Form.Size.Height
|
|
End If
|
|
End If
|
|
|
|
' Query the system for an approved size and position.
|
|
SHAppBarMessage(CInt(ABMsg.ABM_QUERYPOS), abd)
|
|
|
|
' Adjust the rectangle, depending on the edge to which the
|
|
' appbar is anchored.
|
|
Select Case abd.uEdge
|
|
Case CInt(ABEdge.ABE_LEFT)
|
|
abd.rc.right = abd.rc.left + Form.Size.Width
|
|
Case CInt(ABEdge.ABE_RIGHT)
|
|
abd.rc.left = abd.rc.right - Form.Size.Width
|
|
Case CInt(ABEdge.ABE_TOP)
|
|
abd.rc.bottom = abd.rc.top + Form.Size.Height
|
|
Case CInt(ABEdge.ABE_BOTTOM)
|
|
abd.rc.top = abd.rc.bottom - Form.Size.Height
|
|
End Select
|
|
|
|
' Pass the final bounding rectangle to the system.
|
|
SHAppBarMessage(CInt(ABMsg.ABM_SETPOS), abd)
|
|
|
|
' Move and size the appbar so that it conforms to the
|
|
' bounding rectangle passed to the system.
|
|
Form.Location = New Point(abd.rc.left, abd.rc.top)
|
|
Dim PSBH = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height
|
|
Dim TaskBarHeight = PSBH - System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height
|
|
Form.Height = Screen.PrimaryScreen.Bounds.Height - TaskBarHeight
|
|
|
|
' MoveWindow(abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, True)
|
|
End Sub
|
|
|
|
End Class
|