Ensuring WPF window is on top all the time even when user clicks another maximised application
- by mttumbledown
Hi
I am trying to ensure my WPF window stays on top as long as it is open. It is acting as a pop-up set to TopMost=true, and a call to the win32 SetWindowPos to TOPMOST. When first opened it appears on top of another running application on the desktop- maximized or not.
If the user activates or uses a window in the application mine loses focus and disappears.
I thought of manipulating the other application window, setting it to a lower z index. How do I find the application window? How do I iterate through all windows? (This question still stands, even if it is not the correct approach).
I would be using SetWindowPos, GetForegroundWindow, GetForegroundWindow, GetDesktopWindow et cetera.
I suspect that as soon as the user clicks in their application that it will still focus it regardless and I am barking up the wrong tree.
At the moment, my application is a black box and I can’t handle it the other way, for example, periodically messaging my app to focus.
I also thought of having a long running background thread which periodically focuses my WPF popup, but need to watch resources and processor.
Kind regards,