I'm writing a program in WPF which will make a Window
appear overlaid on top of a specific Win32 window in another process.
So far this generally works:
- Get the
hWnd
of the window I want to overlay (the target). - Instantiate my overlay window (
class Overlay : Window
) and show it (overlay.Show()
). - Call
SetWinEventHook
for the target for both theLocationChange
andDestroy
events. - In the callback for
SetWinEventHook
forLocationChange
I reposition myOverlay
instance to match the rectangle of the target window.
The problem is that my Overlay
instance appears behind the target window in the z-axis. I can work-around this by setting Topmost = true
, but then my window is on top of all windows, not just the target.
I tried calling SetParent( new WindowInteropHelper( overlay ).Handle, targetWindowHandle )
however when this happens my overlay window disappears. Calling overlay.Show()
has no effect. I also tried it with SetWindowLongPtr
(though MSDN says not to call this with GWL_HWNDPARENT
) to no avail.
Why does SetParent
make my window invisible, and what's the best way (if not this) to ensure my window remains on-top of another specific window?