shappbarmessage cont.

G

Guest

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 wrong I would be very grateful as I am just
about to eject my laptop through my front window.

Private Declare Function SHAppBarMessage
Lib "shell32.dll" Alias "SHAppBarMessage" (ByVal
dwMessage As Integer, ByRef pData As APPBARDATA) As
Integer
Private Declare Function SetWindowPos Lib "user32"
(ByVal hwnbd As IntPtr, ByVal hWndInsertAfter As Long,
ByVal x As Long, ByVal y As Long, ByVal cX As Long, ByVal
cY As Long, ByVal wFlags As Long) As Long
Structure APPBARDATA
Public cbSize As Long
Public hwnd As IntPtr
Public uCallbackMessage As [Delegate]
Public uEdge As Integer
Public rc As RECT
Public lParam As Integer
End Structure
Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure

Private BarData As APPBARDATA
'constants
'Private Const ABE_LEFT = 0
'Private Const ABE_TOP = 1
Private Const ABE_RIGHT = 2
'Private Const ABE_BOTTOM = 3
'Private Const ABM_GETAUTOHIDEBAR = &H7
Private Const ABM_NEW = &H0
Private Const ABM_REMOVE = &H1
' Private Const ABM_SETAUTOHIDEBAR = &H8
Private Const ABM_SETPOS = &H3
Private Const ABM_GETTASKBARPOS = &H5
'Private Const HWND_TOP = 0
Private Const HWND_TOPMOST = -1
'Private Const SHOWNORMAL = 5
Private Const SWP_NOACTIVATE = &H10
'Private Const SWP_NOSIZE = &H1
'Private Const SWP_NOMOVE = &H2
'Private Const SWP_SHOWWINDOW = &H40
Private Const MY_WINDOWFULLWIDTH = 170
Private Const MY_WINDOWTHINWIDTH = 16

Public Sub DockOnEdge(ByRef myForm As Form, Optional
ByVal Shrink As Boolean = False)
Dim FormWidth As Integer
Dim ScreenWidth, ScreenHeight As Integer
Dim DesiredLeft, DesiredTop, DesiredWidth,
DesiredHeight As Long
'width to set when collapsing
If Shrink = True Then
FormWidth = 16
Else
FormWidth = 170
End If

'unregister if already registered
If BarData.hwnd.ToInt32 <> 0 Then
Call SHAppBarMessage(ABM_REMOVE, BarData)
Else

End If

ScreenWidth =
SystemInformation.PrimaryMonitorSize.Width
ScreenHeight =
SystemInformation.PrimaryMonitorSize.Height

DesiredLeft = ScreenWidth - FormWidth
DesiredTop = 0
DesiredWidth = ScreenWidth - (ScreenWidth -
FormWidth)
DesiredHeight = ScreenHeight

SetWindowPos(myForm.Handle, HWND_TOPMOST,
DesiredLeft, DesiredTop, DesiredWidth, DesiredHeight,
SWP_NOACTIVATE)

BarData.hwnd = myForm.Handle

SHAppBarMessage(ABM_NEW, BarData) <------
Error here

'sets the bardata RECT to the screensize
BarData.rc.left = 0
BarData.rc.top = 0
BarData.rc.right = ScreenWidth
BarData.rc.bottom = ScreenHeight

With BarData
.uEdge = ABE_RIGHT
.rc.top = 0
.rc.left = ScreenWidth - FormWidth
.rc.right = ScreenWidth
.rc.bottom = ScreenHeight
'reserve the area of the screen
SHAppBarMessage(ABM_SETPOS, BarData)
'set the window to the reserved area (which
may be different from the requested)
SetWindowPos(myForm.Handle,
HWND_TOPMOST, .rc.left, .rc.top, .rc.right -
.rc.left, .rc.bottom - .rc.top, SWP_NOACTIVATE)
End With

End Sub



tia

Dan
 
K

Ken Tucker [MVP]

Hi,

Change all the longs to integer.

Ken
--------------------
danspam said:
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 wrong I would be very grateful as I am just
about to eject my laptop through my front window.

Private Declare Function SHAppBarMessage
Lib "shell32.dll" Alias "SHAppBarMessage" (ByVal
dwMessage As Integer, ByRef pData As APPBARDATA) As
Integer
Private Declare Function SetWindowPos Lib "user32"
(ByVal hwnbd As IntPtr, ByVal hWndInsertAfter As Long,
ByVal x As Long, ByVal y As Long, ByVal cX As Long, ByVal
cY As Long, ByVal wFlags As Long) As Long
Structure APPBARDATA
Public cbSize As Long
Public hwnd As IntPtr
Public uCallbackMessage As [Delegate]
Public uEdge As Integer
Public rc As RECT
Public lParam As Integer
End Structure
Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure

Private BarData As APPBARDATA
'constants
'Private Const ABE_LEFT = 0
'Private Const ABE_TOP = 1
Private Const ABE_RIGHT = 2
'Private Const ABE_BOTTOM = 3
'Private Const ABM_GETAUTOHIDEBAR = &H7
Private Const ABM_NEW = &H0
Private Const ABM_REMOVE = &H1
' Private Const ABM_SETAUTOHIDEBAR = &H8
Private Const ABM_SETPOS = &H3
Private Const ABM_GETTASKBARPOS = &H5
'Private Const HWND_TOP = 0
Private Const HWND_TOPMOST = -1
'Private Const SHOWNORMAL = 5
Private Const SWP_NOACTIVATE = &H10
'Private Const SWP_NOSIZE = &H1
'Private Const SWP_NOMOVE = &H2
'Private Const SWP_SHOWWINDOW = &H40
Private Const MY_WINDOWFULLWIDTH = 170
Private Const MY_WINDOWTHINWIDTH = 16

Public Sub DockOnEdge(ByRef myForm As Form, Optional
ByVal Shrink As Boolean = False)
Dim FormWidth As Integer
Dim ScreenWidth, ScreenHeight As Integer
Dim DesiredLeft, DesiredTop, DesiredWidth,
DesiredHeight As Long
'width to set when collapsing
If Shrink = True Then
FormWidth = 16
Else
FormWidth = 170
End If

'unregister if already registered
If BarData.hwnd.ToInt32 <> 0 Then
Call SHAppBarMessage(ABM_REMOVE, BarData)
Else

End If

ScreenWidth =
SystemInformation.PrimaryMonitorSize.Width
ScreenHeight =
SystemInformation.PrimaryMonitorSize.Height

DesiredLeft = ScreenWidth - FormWidth
DesiredTop = 0
DesiredWidth = ScreenWidth - (ScreenWidth -
FormWidth)
DesiredHeight = ScreenHeight

SetWindowPos(myForm.Handle, HWND_TOPMOST,
DesiredLeft, DesiredTop, DesiredWidth, DesiredHeight,
SWP_NOACTIVATE)

BarData.hwnd = myForm.Handle

SHAppBarMessage(ABM_NEW, BarData) <------
Error here

'sets the bardata RECT to the screensize
BarData.rc.left = 0
BarData.rc.top = 0
BarData.rc.right = ScreenWidth
BarData.rc.bottom = ScreenHeight

With BarData
.uEdge = ABE_RIGHT
.rc.top = 0
.rc.left = ScreenWidth - FormWidth
.rc.right = ScreenWidth
.rc.bottom = ScreenHeight
'reserve the area of the screen
SHAppBarMessage(ABM_SETPOS, BarData)
'set the window to the reserved area (which
may be different from the requested)
SetWindowPos(myForm.Handle,
HWND_TOPMOST, .rc.left, .rc.top, .rc.right -
.rc.left, .rc.bottom - .rc.top, SWP_NOACTIVATE)
End With

End Sub



tia

Dan
 

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