Question

I create a popup window (WS_POPUP, WS_EX_TOPMOST, WS_EX_TOOLWINDOW) that can receive focus when clicked (by calling SetFocus in WM_LBUTTONDOWN handler). All works well until I minimize the main application window (the popup is still visible) - now when I click the popup, it immediately loses focus again. Why is that happening, shouldn't the popup window be completely unrelated to the main window, since its not a child or anything?

Update: this seems to be related to WS_POPUP. Attempting to click a window while the main application window is minimized flashes its taskbar icon and immediately kills focus.

Was it helpful?

Solution 2

Found an interesting solution which happens to solve my other problem as well (if the popup is shown over a fullscreen game, clicking it will cause the taskbar to appear) - I made the window transparent (WS_EX_TRANSPARENT) and handled mouse and keyboard through system-wide hooks. The only drawback is that I have to let mouse movement through because blocking it would cause the cursor to stop (and because of this, I can't change the cursor as the app behind my popup would just change it back).

OTHER TIPS

The purpose of clicking on a window is to activate the application. If a window is visible but not owned (as in your case) then Windows is not able to activate the application when the window is clicked. This is the (expected) behaviour you are seeing.

If there is something in particular you want to accomplish then you should still see messages for that window coming through the message loop. Keyboard messages are only sent to the window with focus. Mouse messages are sent to the window that has captured the mouse (if there is one), or to the topmost window under the mouse pointer (which is found by hit testing) whether it has focus or not. various other messages may be sent to the window if the need arises (paint for example).

If you want your popup window to take focus, then it must have a top level parent window that can be activated. The usual solution is to create an invisible top level window (1 pixel or off screen) to be its parent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top