Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Imports System.Runtime.InteropServices
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
RegisterBar()
End Sub
Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
RegisterBar()
End Sub
#Region " AppBar "
<StructLayout(LayoutKind.Sequential)> 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 IntPtr
End Structure
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
Enum ABNotify
ABN_STATECHANGE = 0
ABN_POSCHANGED
ABN_FULLSCREENAPP
ABN_WINDOWARRANGE
End Enum
Enum ABEdge
ABE_LEFT = 0
ABE_TOP
ABE_RIGHT
ABE_BOTTOM
End Enum
Private fBarRegistered As Boolean = False
<DllImport("SHELL32", CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function SHAppBarMessage(ByVal dwMessage As Integer, ByRef BarrData As APPBARDATA) As Integer
End Function
<DllImport("USER32")> _
Public Shared Function GetSystemmetric(ByVal Index As Integer) As Integer
End Function
<DllImport("User32.dll", ExactSpelling:=True, CharSet:=System.Runtime.InteropServices.CharSet.Auto)> _
Public 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)> _
Public Shared Function RegisterWindowMessage(ByVal msg As String) As Integer
End Function
Private uCallBack As Integer
Private Sub RegisterBar()
Dim abd As New APPBARDATA
Dim ret As Integer
abd.cbSize = Marshal.SizeOf(abd)
abd.hWnd = Me.Handle
If fBarRegistered Then
uCallBack = RegisterWindowMessage("AppBarMessage")
abd.uCallbackMessage = uCallBack
ret = SHAppBarMessage(ABMsg.ABM_NEW, abd)
fBarRegistered = True
ABSetPos()
Else
ret = SHAppBarMessage(ABMsg.ABM_REMOVE, abd)
fBarRegistered = False
End If
End Sub
Private Sub ABSetPos()
Dim abd As New APPBARDATA
abd.cbSize = Marshal.SizeOf(abd)
abd.hWnd = Me.Handle
abd.uEdge = ABEdge.ABE_TOP
If abd.uEdge = ABEdge.ABE_LEFT OrElse abd.uEdge = ABEdge.ABE_RIGHT Then
abd.rc.top = 0
abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height
If abd.uEdge = ABEdge.ABE_LEFT Then
abd.rc.left = 0
abd.rc.right = Size.Width
Else
abd.rc.right = SystemInformation.PrimaryMonitorSize.Width
abd.rc.left = abd.rc.right - Size.Width
End If
Else
abd.rc.left = 0
abd.rc.right = SystemInformation.PrimaryMonitorSize.Width
If abd.uEdge = ABEdge.ABE_TOP Then
abd.rc.top = 0
abd.rc.bottom = Size.Height
Else
abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height
abd.rc.top = abd.rc.bottom - Size.Height
End If
End If
'Query the system for an approved size and position.
SHAppBarMessage(ABMsg.ABM_QUERYPOS, abd)
'Adjust the rectangle, depending on the edge to which the appbar is anchored.
Select Case abd.uEdge
Case ABEdge.ABE_LEFT
abd.rc.right = abd.rc.left + Size.Width
Case ABEdge.ABE_RIGHT
abd.rc.left = abd.rc.right - Size.Width
Case ABEdge.ABE_TOP
abd.rc.bottom = abd.rc.top + Size.Height
Case ABEdge.ABE_BOTTOM
abd.rc.top = abd.rc.bottom - Size.Height
End Select
'Pass the final bounding rectangle to the system.
SHAppBarMessage(ABMsg.ABM_SETPOS, abd)
'Move and size the appbar so that it conforms to the bounding rectangle passed to the system.
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 Region
If [b]Not[/b] fBarRegistered Then
..
Else
..
End If
[COLOR=blue]Public Sub[/color] RegisterBar([COLOR=blue]ByVal[/color] frm [COLOR=blue]As[/color] Form, [COLOR=blue]Optional ByVal[/color] dockEdge [COLOR=blue]As[/color] ABEdge = [i]myDefault position[/i])