adam_pedley
asked on
Create an Application Bar (app bar)
Hi
This is just a reference for people looking for a vb .net version of the code for creating an application bar since myself and others couldn't find one
Anyone wanting to say hello can get the accepted answer for this just to keep it up here. It is listed in another question but the title of it doesn't suit the solution.
It was converted from http://www.codeproject.com/Purgatory/AppBar.asp which is a c# version
Here is the code
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Runtime.InteropServ ices
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon tainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Butto n
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Butto n()
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(72, 80)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(80, 40)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Close"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1 )
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RegisterBar()
End Sub
Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure 'RECT
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 'APPBARDATA
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
Public Declare Function SHAppBarMessage Lib "shell32.dll" Alias "SHAppBarMessage" (ByVal dwMessage As Integer, ByRef pData As APPBARDATA) As System.UInt32
Public Declare Function GetSystemMetrics Lib "User32.dll" Alias "GetSystemMetrics" (ByVal index As Integer) As Integer
Public Declare Function MoveWindow Lib "User32.dll" Alias "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
Private Declare Auto Function RegisterWindowMessage Lib "User32.dll" (ByVal msg As String) As Integer
Private uCallBack As Integer
Private Sub RegisterBar()
Dim abd As New APPBARDATA()
abd.cbSize = Marshal.SizeOf(abd)
abd.hWnd = Me.Handle
If Not fBarRegistered Then
uCallBack = RegisterWindowMessage("App BarMessage ")
abd.uCallbackMessage = uCallBack
Dim ret As System.UInt32 = SHAppBarMessage(CInt(ABMsg .ABM_NEW), abd) 'ToDo: Unsigned Integers not supported
fBarRegistered = True
ABSetPos()
Else
SHAppBarMessage(CInt(ABMsg .ABM_REMOV E), abd)
fBarRegistered = False
End If
End Sub 'RegisterBar
Private Sub ABSetPos()
Dim abd As New APPBARDATA()
abd.cbSize = Marshal.SizeOf(abd)
abd.hWnd = Me.Handle
abd.uEdge = CInt(ABEdge.ABE_TOP)
If abd.uEdge = CInt(ABEdge.ABE_LEFT) Or abd.uEdge = CInt(ABEdge.ABE_RIGHT) Then
abd.rc.top = 0
abd.rc.bottom = SystemInformation.PrimaryM onitorSize .Height
If abd.uEdge = CInt(ABEdge.ABE_LEFT) Then
abd.rc.left = 0
abd.rc.right = Size.Width
Else
abd.rc.right = SystemInformation.PrimaryM onitorSize .Width
abd.rc.left = abd.rc.right - Size.Width
End If
Else
abd.rc.left = 0
abd.rc.right = SystemInformation.PrimaryM onitorSize .Width
If abd.uEdge = CInt(ABEdge.ABE_TOP) Then
abd.rc.top = 0
abd.rc.bottom = Size.Height
Else
abd.rc.bottom = SystemInformation.PrimaryM onitorSize .Height
abd.rc.top = abd.rc.bottom - Size.Height
End If
End If
' Query the system for an approved size and position.
SHAppBarMessage(CInt(ABMsg .ABM_QUERY POS), 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 + Size.Width
Case CInt(ABEdge.ABE_RIGHT)
abd.rc.left = abd.rc.right - Size.Width
Case CInt(ABEdge.ABE_TOP)
abd.rc.bottom = abd.rc.top + Size.Height
Case CInt(ABEdge.ABE_BOTTOM)
abd.rc.top = abd.rc.bottom - Size.Height
End Select
' Pass the final bounding rectangle to the system.
SHAppBarMessage(CInt(ABMsg .ABM_SETPO S), 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 'ABSetPos
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Messa ge)
If m.Msg = uCallBack Then
Select Case m.WParam.ToInt32()
Case CInt(ABNotify.ABN_POSCHANG ED)
ABSetPos()
End Select
End If
MyBase.WndProc(m)
End Sub 'WndProc
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.Creat eParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style And Not &HC00000 ' WS_CAPTION
cp.Style = cp.Style And Not &H800000 ' WS_BORDER
cp.ExStyle = &H80 Or &H8 ' WS_EX_TOOLWINDOW | WS_EX_TOPMOST
Return cp
End Get
End Property
Private Sub End_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RegisterBar()
End
End Sub
End Class
This is just a reference for people looking for a vb .net version of the code for creating an application bar since myself and others couldn't find one
Anyone wanting to say hello can get the accepted answer for this just to keep it up here. It is listed in another question but the title of it doesn't suit the solution.
It was converted from http://www.codeproject.com/Purgatory/AppBar.asp which is a c# version
Here is the code
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Runtime.InteropServ
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Butto
<System.Diagnostics.Debugg
Me.Button1 = New System.Windows.Forms.Butto
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(72, 80)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(80, 40)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Close"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
RegisterBar()
End Sub
Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure 'RECT
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 'APPBARDATA
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
Public Declare Function SHAppBarMessage Lib "shell32.dll" Alias "SHAppBarMessage" (ByVal dwMessage As Integer, ByRef pData As APPBARDATA) As System.UInt32
Public Declare Function GetSystemMetrics Lib "User32.dll" Alias "GetSystemMetrics" (ByVal index As Integer) As Integer
Public Declare Function MoveWindow Lib "User32.dll" Alias "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
Private Declare Auto Function RegisterWindowMessage Lib "User32.dll" (ByVal msg As String) As Integer
Private uCallBack As Integer
Private Sub RegisterBar()
Dim abd As New APPBARDATA()
abd.cbSize = Marshal.SizeOf(abd)
abd.hWnd = Me.Handle
If Not fBarRegistered Then
uCallBack = RegisterWindowMessage("App
abd.uCallbackMessage = uCallBack
Dim ret As System.UInt32 = SHAppBarMessage(CInt(ABMsg
fBarRegistered = True
ABSetPos()
Else
SHAppBarMessage(CInt(ABMsg
fBarRegistered = False
End If
End Sub 'RegisterBar
Private Sub ABSetPos()
Dim abd As New APPBARDATA()
abd.cbSize = Marshal.SizeOf(abd)
abd.hWnd = Me.Handle
abd.uEdge = CInt(ABEdge.ABE_TOP)
If abd.uEdge = CInt(ABEdge.ABE_LEFT) Or abd.uEdge = CInt(ABEdge.ABE_RIGHT) Then
abd.rc.top = 0
abd.rc.bottom = SystemInformation.PrimaryM
If abd.uEdge = CInt(ABEdge.ABE_LEFT) Then
abd.rc.left = 0
abd.rc.right = Size.Width
Else
abd.rc.right = SystemInformation.PrimaryM
abd.rc.left = abd.rc.right - Size.Width
End If
Else
abd.rc.left = 0
abd.rc.right = SystemInformation.PrimaryM
If abd.uEdge = CInt(ABEdge.ABE_TOP) Then
abd.rc.top = 0
abd.rc.bottom = Size.Height
Else
abd.rc.bottom = SystemInformation.PrimaryM
abd.rc.top = abd.rc.bottom - Size.Height
End If
End If
' Query the system for an approved size and position.
SHAppBarMessage(CInt(ABMsg
' 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 + Size.Width
Case CInt(ABEdge.ABE_RIGHT)
abd.rc.left = abd.rc.right - Size.Width
Case CInt(ABEdge.ABE_TOP)
abd.rc.bottom = abd.rc.top + Size.Height
Case CInt(ABEdge.ABE_BOTTOM)
abd.rc.top = abd.rc.bottom - Size.Height
End Select
' Pass the final bounding rectangle to the system.
SHAppBarMessage(CInt(ABMsg
' 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 'ABSetPos
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Messa
If m.Msg = uCallBack Then
Select Case m.WParam.ToInt32()
Case CInt(ABNotify.ABN_POSCHANG
ABSetPos()
End Select
End If
MyBase.WndProc(m)
End Sub 'WndProc
Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.Creat
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style And Not &HC00000 ' WS_CAPTION
cp.Style = cp.Style And Not &H800000 ' WS_BORDER
cp.ExStyle = &H80 Or &H8 ' WS_EX_TOOLWINDOW | WS_EX_TOPMOST
Return cp
End Get
End Property
Private Sub End_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RegisterBar()
End
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well considering how hard it is sometimes to find information regarding such things
Example my no_activate window question
https://www.experts-exchange.com/questions/21158924/Loading-a-Form-with-the-no-activate-option.html
There was nothing on the net about it except one post on experts exchange which only showed it in delphi
Big thanks again to idle_mind for that solution
My post was up there for about 5 days without a reply, which is very rare here
Example my no_activate window question
https://www.experts-exchange.com/questions/21158924/Loading-a-Form-with-the-no-activate-option.html
There was nothing on the net about it except one post on experts exchange which only showed it in delphi
Big thanks again to idle_mind for that solution
My post was up there for about 5 days without a reply, which is very rare here
Good of you to post it like this, It will certainly help some people.
RB