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.
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
=============================================
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....
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.
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.
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.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.