473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with SHAppBarMessage

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
Jan 17 '06 #1
4 2479
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
Jan 17 '06 #2
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ó:
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

Jan 17 '06 #3
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

"Dragon" wrote:
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

Jan 17 '06 #4
I have the solution:
I have had to change this line. The FormBorderStyle must be FixedToolWindow

Me.FormBorderStyle =
system.Windows.Forms.FormBorderStyle.FixedToolWind ow

"Daavi" wrote:
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

Jan 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

117
by: Peter Olcott | last post by:
www.halting-problem.com
2
by: danspam | last post by:
Has anyone managed to get this shell api call to work in vb.net? I keep getting a system.nullreference exception when trying to use it. My code works fine in vb6 but when I translate it to vb.net...
1
by: danspam | last post by:
Thanks for the replies but they did not help me as I am trying to regiseter a form as an appbar and C sharp is no good to me! Anyway my code is as follows. If anyone can spot what I am doing...
0
by: Daavi | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.