I am working with a software developer on a C Program that has a floating preferences window. If I use the Windows taskbar to switch to another program when mine is running, my floating window still resides over the program I switched to. I am not a programmer and I am being told by my programmer that there is no way to prevent this. I am told he is using SetWindowPosition and something called TOPMOST to give this window it's privilege to stay on top. I like it being on top while working in my program but not when I switch to another program.
Is there something I can tell him to do so that this window does not remain topmost when I switch to another program but stays on top when I return to my program?
You can use the
WM_ACTIVATE
message. Windows sends this message when a window is activated or deactivated. If the user switches to another application the current window of your application receives aWM_ACTIVATE
message telling it that it is being deactivated.Here is a little example to set/remove the topmost flag when the user switches to another application (considering the
hFloatingWindow
is the window handle to your floating window):Note that you have to add the code of
WM_ACTIVATE
to all window procedures of your application. This is neccessary since the user can switch to another task from any of your windows being active. And if the currently active window does not handle theWM_ACTIVATE
message as shown above the topmost flag will not be removed.