[try Beta version]
Not logged in

 
Run program and make window active

Jan 5, 2023 at 9:32pm
How do I run a program with win32 context as active? Currently it is always shown as inactive.

I already used SetFocus(handle) and still inactive.
Last edited on Jan 5, 2023 at 11:46pm
Jan 6, 2023 at 6:16pm
are you asking about always-on-top type behavior? or something else?
Jan 6, 2023 at 7:39pm
What are you trying to accomplish? There are several WIN32 APIs:
BringTofront()
Activate()
SetActiveWindow()
SetForegroundWindow()
BringWindowToTop()
SetWindowPos()
Last edited on Jan 6, 2023 at 7:44pm
Jan 7, 2023 at 3:00pm
SetActiveWindow() and BringWindowToTop() only changes the Z-order of your windows and sets the "active" window within the calling application. It does not bring your application to the foreground, if another application is currently in the foreground!


SetForegroundWindow() is used to actually bring a window to the foreground. This can be a window of the calling application, or a window belonging to another application. But: The call to SetForegroundWindow() will only succeed, if the current foreground window belongs to the calling application, or if the calling application was created by the application owning the current foreground window.

The actual rules are a bit more complex:
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setforegroundwindow

In other words: Stealing the focus from the current "foreground" application by calling SetForegroundWindow() from a "background" application is not possible – in "modern" versions of Windows. And that is for good reasons 😏


BTW: You can use SetWindowLongW() with GWL_EXSTYLE and WS_EX_TOPMOST to enable the "topmost" style for your window, so that it will appear on top of all other windows, regardless of whether your application is currently active or not...
Last edited on Jan 7, 2023 at 3:12pm
Jan 14, 2023 at 5:14am
Thanks guys. I think this has something to do with parenting a child window to a main window which is sort of a hack or maybe there's a right way to do it?

I tried again without the child window and the window is active and focus when starting as it should be.
Last edited on Jan 14, 2023 at 5:16am
Topic archived. No new replies allowed.