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

    Window on top & help problem

    Hi,
    I'm having a problem with a program containing a "What's this" help button and a checkbox with the option to keep the program on top.

    Code:
       App.HelpFile = AppDir & "Eurohelp.chm::popups.txt"
    Code:
    Private Sub Check1_Click()
        If Check1.Value = 1 Then
            'stay on top
            SetWindowPos frmMain.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
        Else
            'Don't stay on top
            SetWindowPos frmMain.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
        End If
    End Sub
    When the checkbox is unchecked (and the program is not kept on top), then the help works perfectly. However, when the program is set to topmost, the help is not displayed.

    I'm guessing this happens because the main window always forces itself to the top, and in doing so places itself above the help text.

    Does anybody know of a way to fix this? Thanx

  2. #2
    Join Date
    Oct 2009
    Posts
    12

    Re: Window on top & help problem

    dear,

    I'm using a checkbox with style=1-Graphical and the code=
    =============================================
    Private Sub Check_TopMost_Click()
    If Check_TopMost Then
    SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
    Else
    SetWindowPos hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
    End If
    End Sub
    =============================================

  3. #3
    Join Date
    Nov 2005
    Posts
    18

    Re: Window on top & help problem

    Thanks for your reply

    The problem is not with the keep-this-window-on-top code, however. That part works okay. And when the window is not set as the topmost, the 'what's this'-help works okay, too.
    Only when the window is set topmost, the 'what's this'-help refuses to work correctly. The windows loses focus (but stays on top), but no help is displayed....

  4. #4
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: Window on top & help problem

    Does the help window display at all?
    If so, then set it topmost too.

    This sounds like the same flaw you get with "modal-like windows", under top most windows.
    This is especially annoying, when the top window is maximized over the focused window, and the taskbar is unreachable.
    Sometimes, you end up having to reboot.

    Microsoft should really fix this, and not rely on developers, to somehow already know that these two things could conflict.

    Until then, the issue still remains, that other modal windows could be covered at any time, by any other top program, in a multi-task environment.

  5. #5
    Join Date
    Nov 2005
    Posts
    18

    Re: Window on top & help problem

    Yes, the help appears, but is pushed below the app window.

    I've included a screenshot that shows the problem... Setting the help text boxes topmost would probably solve the problem, but how can I do that?

    (Btw: the screenshot show the help for the clear button...)
    Attached Images Attached Images  

  6. #6
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: Window on top & help problem

    Oh, okay so it's not a big window, just the little tool tip window.
    I did a quick search and came up with this:

    http://frogleg.mvps.org/helptechnolo.../hhvbclas.html

    One interesting result of this work is that it fixes an irritating problem with using HTML Help-based What's This topics in Visual Basic 6 with versions of hhctrl.ocx earlier than 4.74.8637. This is where the popup appears behind the application, and the only indication that the popup has been created is a blank button on the taskbar. Clicking the button on the taskbar brings the popup to the front where it can be read. Testing has proven that using the technique described in the class module's documentation for the HHSubClass procedure fixes this problem. The popups subsequently appear in front of the application 100% of the time.
    Although, I was thinking of using FindWindowEx, to find the "what's this" window by it's class name.
    I'm not sure what the class name actually is off hand, but you could look it up online somewhere.
    You might user a timer, to continually check for this window, and set it topmost.

  7. #7
    Join Date
    Nov 2005
    Posts
    18

    Re: Window on top & help problem

    The FindWindowEx technique seems to be the better choice, but I have no idea on how to find the class name, or how to implement this technique.

    Could you please explain this a bit for me? Perhaps by example?

  8. #8
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: Window on top & help problem

    FindWindowEx seems like the simplest answer, if it works

    Code:
    Private Declare Function apiFindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Code:
    Private Sub Timer1_Timer()
            Dim cwnd As Long
            Dim cName As String
     
            cName = "WindowsClassNameHere"
    
            'Try this first
            cwnd = apiFindWindowEx (frmMain.hwnd, 0, cName, vbNullString)
           
           'Try uncommenting this if it's not a child of the main form
            'cwnd = apiFindWindowEx (0, 0, cName, vbNullString)
    
             'Display result in the caption, just so you know when the handle is found or not
             Me.Caption = CStr(cwnd) 
    
             If cwnd = 0 Then Exit Sub 
    
            SetWindowPos cwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
    
    End Sub

    However that link, has a module that definately has the API you need to more directly achieve this.
    The complexity level is much greater than FindWindowEx, so the simplest solution is preferable when possible.

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