January 17th, 2012, 05:00 PM
AppBar - What the diddly?
I have a weird issue with my very first appbar that I have been fighting for days with.
Below is Sub Show() that either creates an appbar and puts it just above the taskbar scooching
the desktop apps up by the size of the appbar, or deletes the appbar and hides the form.
The Flag WasHidden is a 1 if the form and appbar space is not there or a 0 if they (the appbar space and the docked form within) are shown. This Sub is called in response to a hotkey to toggle on and off the docked form and the desktop space it occupies.
At program startup, WasHidden is initialized to a 1 so the appbar is created and the form docks there. This works all the time. If I use the hotkey then the sub turns off the form and deletes the appbar from windows list. This also works every time.
However, if I use the hotkey once again to turn on the form the appbar is created where it should be but the form is displayed over the bottom of the main desktop app and cannot be dragged into the appbar below as if windows does not think it belongs there. - this is the case ever time.
I found however that if I set a break point at the SetWindowPos line then let it rip with an F5 (run) then the form will always load in the docking space like it should. Now matter how quickly I press f5 to run after the breakpoint, it always behaves as it should as if there is a race condition somewhere.
I have no timers at all in this app.
It is being developed on an old XP SP3 laptop.
What could be happening to me!?
Thanks in advance,
Public Sub show()
Dim abd As APPBARDATA
abd.cbSize = Len(abd)
abd.hwnd = m_frmCons.hwnd
If WasHidden = 1 Then
WasHidden = 0
abd.uEdge = ABE_BOTTOM
SetRect abd.rc, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)
SHAppBarMessage ABM_QUERYPOS, abd
Select Case abd.uEdge
abd.rc.Right = abd.rc.Left + WIDTH_WHEN_DOCKED_LEFT
abd.rc.Left = abd.rc.Right - WIDTH_WHEN_DOCKED_RIGHT
abd.rc.Top = abd.rc.Bottom - WIDTH_WHEN_DOCKED_BOTTOM
abd.rc.Bottom = abd.rc.Top + WIDTH_WHEN_DOCKED_TOP
SHAppBarMessage ABM_SETPOS, abd
''***************** If I break at the line below, then let 'er rip it works **************
''****************** If I let it run through without the breakpoint it will mis-position the ''*******************form - every time
SetWindowPos abd.hwnd, 0, abd.rc.Left, abd.rc.Top, (abd.rc.Right - abd.rc.Left), (abd.rc.Bottom - abd.rc.Top), SWP_NOZORDER Or SWP_NOACTIVATE
Else '' was shown - need to hide appbar now
WasHidden = 1
Call SHAppBarMessage(ABM_REMOVE, abd)
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.