Problem with SHAppBarMessage

G

Guest

Hi group,
I have this code for create a appbar like windows taskbar, but don't work :(
If remove the next line from Button1_Click
SHAppBarMessage(ABM_REMOVE, abd)
when finish app keep desktop area and work perfectly when restart app
Please help!!


Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Code "

Public Sub New()
MyBase.New()

InitializeComponent()

End Sub

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

Private components As System.ComponentModel.IContainer

Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(8, 8)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(74, 36)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Declare Function SHAppBarMessage Lib "shell32.dll" Alias
"SHAppBarMessage" (ByVal dwMessage As Integer, ByRef pData As APPBARDATA) As
Integer
Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Integer,
ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer,
ByVal cX As Integer, ByVal cY As Integer, ByVal wFlags As Integer) As Integer
Structure APPBARDATA
Dim cbSize As Integer
Dim hwnd As Integer
Dim uCallbackMessage As [Delegate]
Dim uEdge As Integer
Dim rc As RECT
Dim lParam As Integer ' message specific
End Structure
Structure RECT
Dim Left As Integer
Dim Top As Integer
Dim Right As Integer
Dim Bottom As Integer
End Structure
Const ABE_LEFT As Integer = 0
Const ABE_TOP As Integer = &H1
Const ABE_RIGHT As Integer = 2
Const ABE_BOTTOM As Integer = 3

Const ABM_NEW As Integer = 0
Const ABM_REMOVE As Integer = 1
Const ABM_QUERYPOS As Integer = 2
Const ABM_SETPOS As Integer = &H3
Const ABM_GETSTATE As Integer = 4
Const ABM_GETTASKBARPOS As Integer = 5
Const ABM_ACTIVATE As Integer = 6
Const ABM_GETAUTOHIDEBAR As Integer = 7
Const ABM_SETAUTOHIDEBAR As Integer = 8
Const ABM_WINDOWPOSCHANGED As Integer = 9

Const ABS_AUTOHIDE As Integer = 1
Const ABS_ALWAYSONTOP As Integer = 2

Const HWND_NOTTOPMOST As Integer = -2
Const HWND_TOPMOST As Integer = -1
Const HWND_TOP As Integer = 0
Const SHOWNORMAL As Integer = 5

Const SWP_NOMOVE As Integer = 2
Const SWP_NOSIZE As Integer = 1
Const SWP_NOZORDER As Integer = 4
Const SWP_NOACTIVATE As Integer = &H10
Const SWP_DRAWFRAME As Integer = &H20
Const SWP_SHOWWINDOW As Integer = &H40

Dim abd As APPBARDATA
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
abd.hwnd = Me.Handle.ToInt32
abd.cbSize = Len(abd)
With abd
.uEdge = ABE_RIGHT
.rc.Top = 0
.rc.Left = Screen.PrimaryScreen.Bounds.Width - 100
.rc.Right = Screen.PrimaryScreen.Bounds.Width
.rc.Bottom = Screen.PrimaryScreen.Bounds.Height
SHAppBarMessage(ABM_NEW, abd)
SetWindowPos(abd.hwnd, HWND_TOP, .rc.Left, .rc.Top, .rc.Right -
..rc.Left, .rc.Bottom, SWP_SHOWWINDOW Or SWP_NOACTIVATE)
SHAppBarMessage(ABM_SETPOS, abd)
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
SHAppBarMessage(ABM_REMOVE, abd)
End
End Sub
End Class
 
D

Dragon

Hi,

If the problem is that the appbar doesn't move to a desired location,
try this:

~
SHAppBarMessage(ABM_SETPOS, abd)
Me.SetBounds(.rc.Left, .rc.Top, .rc.Right - .rc.Left,
..rc.Bottom)
~

instead of

~
SetWindowPos(abd.hwnd, HWND_TOP, .rc.Left, .rc.Top,
..rc.Right - .rc.Left, .rc.Bottom, SWP_SHOWWINDOW Or SWP_NOACTIVATE)
SHAppBarMessage(ABM_SETPOS, abd)
~

Also, in APPBARDATA definition, change uCallbackMessage to be Integer
and hwnd to be IntPtr.

HTH,
Roman
 
G

Guest

Thx for your answer.
Exactly, the appbar doesn't move to the desired position outside of my
desktop workarea and remains inside the workarea
Your code does the same thing than mine.
Daavi

"Dragon" escribió:
 
G

Guest

Thx for your answer.
Exactly, the appbar doesn't move to the desired position outside of my
desktop workarea and remains inside the workarea.
Your code does the same thing that mine.
Regards,
Daavi
 
G

Guest

I have the solution:
I have had to change this line. The FormBorderStyle must be FixedToolWindow

Me.FormBorderStyle =
system.Windows.Forms.FormBorderStyle.FixedToolWindow



Daavi said:
Hi group,
I have this code for create a appbar like windows taskbar, but don't work :(
If remove the next line from Button1_Click
SHAppBarMessage(ABM_REMOVE, abd)
when finish app keep desktop area and work perfectly when restart app
Please help!!


Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Code "

Public Sub New()
MyBase.New()

InitializeComponent()

End Sub

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

Private components As System.ComponentModel.IContainer

Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(8, 8)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(74, 36)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Declare Function SHAppBarMessage Lib "shell32.dll" Alias
"SHAppBarMessage" (ByVal dwMessage As Integer, ByRef pData As APPBARDATA) As
Integer
Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Integer,
ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer,
ByVal cX As Integer, ByVal cY As Integer, ByVal wFlags As Integer) As Integer
Structure APPBARDATA
Dim cbSize As Integer
Dim hwnd As Integer
Dim uCallbackMessage As [Delegate]
Dim uEdge As Integer
Dim rc As RECT
Dim lParam As Integer ' message specific
End Structure
Structure RECT
Dim Left As Integer
Dim Top As Integer
Dim Right As Integer
Dim Bottom As Integer
End Structure
Const ABE_LEFT As Integer = 0
Const ABE_TOP As Integer = &H1
Const ABE_RIGHT As Integer = 2
Const ABE_BOTTOM As Integer = 3

Const ABM_NEW As Integer = 0
Const ABM_REMOVE As Integer = 1
Const ABM_QUERYPOS As Integer = 2
Const ABM_SETPOS As Integer = &H3
Const ABM_GETSTATE As Integer = 4
Const ABM_GETTASKBARPOS As Integer = 5
Const ABM_ACTIVATE As Integer = 6
Const ABM_GETAUTOHIDEBAR As Integer = 7
Const ABM_SETAUTOHIDEBAR As Integer = 8
Const ABM_WINDOWPOSCHANGED As Integer = 9

Const ABS_AUTOHIDE As Integer = 1
Const ABS_ALWAYSONTOP As Integer = 2

Const HWND_NOTTOPMOST As Integer = -2
Const HWND_TOPMOST As Integer = -1
Const HWND_TOP As Integer = 0
Const SHOWNORMAL As Integer = 5

Const SWP_NOMOVE As Integer = 2
Const SWP_NOSIZE As Integer = 1
Const SWP_NOZORDER As Integer = 4
Const SWP_NOACTIVATE As Integer = &H10
Const SWP_DRAWFRAME As Integer = &H20
Const SWP_SHOWWINDOW As Integer = &H40

Dim abd As APPBARDATA
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
abd.hwnd = Me.Handle.ToInt32
abd.cbSize = Len(abd)
With abd
.uEdge = ABE_RIGHT
.rc.Top = 0
.rc.Left = Screen.PrimaryScreen.Bounds.Width - 100
.rc.Right = Screen.PrimaryScreen.Bounds.Width
.rc.Bottom = Screen.PrimaryScreen.Bounds.Height
SHAppBarMessage(ABM_NEW, abd)
SetWindowPos(abd.hwnd, HWND_TOP, .rc.Left, .rc.Top, .rc.Right -
.rc.Left, .rc.Bottom, SWP_SHOWWINDOW Or SWP_NOACTIVATE)
SHAppBarMessage(ABM_SETPOS, abd)
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
SHAppBarMessage(ABM_REMOVE, abd)
End
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top