My window should be on top of a specific "target" window that I don't have control over.
When the target window is activated, I call SetWindowPos
with HWND_TOPMOST
to place my window on top of it while the target can still be the active window.
When the target window is no longer the foreground window, I want my window to still be on top of the target window, but no longer topmost, so other windows are not covered by it.
Two ideas I had:
Call
SetWindowPos
withhWndInsertAfter
to be the just activated window. This fails when the just activated window is topmost, because my window then does not lose the topmost status. Another issue with this: If the just activated window is the desktop, then my window is placed below the target window.Call
SetWindowPos
withHWND_NOTOPMOST
to lose the topmost status. However, this brings my window to the top of all non-topmost windows, so it covers the just activated window. To fix this I have to bring the just activated window on top again with anotherSetWindowPos
withHWND_TOP
. This feels like the wrong way to do it and may cause flicker.
Is it possible to have a window just stop being topmost and placing it below the current foreground window?