CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2011
    Posts
    9

    Question 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,


    :Ron

    -----------------------------------------------------------------------------------------------------------------

    Public Sub show()

    Dim abd As APPBARDATA

    abd.cbSize = Len(abd)
    abd.hwnd = m_frmCons.hwnd

    If WasHidden = 1 Then
    WasHidden = 0
    NewAppBar (m_frmCons.hwnd)

    abd.uEdge = ABE_BOTTOM

    SetRect abd.rc, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)

    SHAppBarMessage ABM_QUERYPOS, abd

    Select Case abd.uEdge
    Case ABE_LEFT
    abd.rc.Right = abd.rc.Left + WIDTH_WHEN_DOCKED_LEFT
    Case ABE_RIGHT
    abd.rc.Left = abd.rc.Right - WIDTH_WHEN_DOCKED_RIGHT
    Case ABE_BOTTOM
    abd.rc.Top = abd.rc.Bottom - WIDTH_WHEN_DOCKED_BOTTOM
    Case ABE_TOP
    abd.rc.Bottom = abd.rc.Top + WIDTH_WHEN_DOCKED_TOP
    End Select

    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

    m_frmCons.show

    Else '' was shown - need to hide appbar now

    WasHidden = 1
    m_frmCons.Hide
    Call SHAppBarMessage(ABM_REMOVE, abd)

    End If

    End Sub

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: AppBar - What the diddly?

    Without going to far into it perhaps inserting a brief sleep statement would solve the issue.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Nov 2011
    Posts
    9

    Re: AppBar - What the diddly?

    Quote Originally Posted by DataMiser View Post
    Without going to far into it perhaps inserting a brief sleep statement would solve the issue.

    I did do that. A full second.
    All that did was delay the inevitable by 1 second

    Thanks for your help.

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: AppBar - What the diddly?

    I once had one strange issue with the SetWindowPos function, too. It would work when running through it in single step, but wouldn't when the program was compiled or simply running.

    I found no reason why this should be, but I could solve the problem by repeating the SetWindowPos call a second time. Please just for curiousity try:
    Code:
    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 'first 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 'another call
    Just a thought that helped me.

  5. #5
    Join Date
    Nov 2011
    Posts
    9

    Re: AppBar - What the diddly?

    Quote Originally Posted by WoF View Post
    I once had one strange issue with the SetWindowPos function, too. It would work when running through it in single step, but wouldn't when the program was compiled or simply running.

    I found no reason why this should be, but I could solve the problem by repeating the SetWindowPos call a second time. Please just for curiousity try:
    Code:
    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 'first 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 'another call
    Just a thought that helped me.
    That's what occurred to me to try! But I thought I would come here first to see if there were any more replys. Then I saw yours, so I tried it. But no joy yet.

    Thanks.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured