2

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:

  1. Get the hWnd of the window I want to overlay (the target).
  2. Instantiate my overlay window (class Overlay : Window) and show it (overlay.Show()).
  3. Call SetWinEventHook for the target for both the LocationChange and Destroy events.
  4. In the callback for SetWinEventHook for LocationChange I reposition my Overlay 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?

Dai
  • 141,631
  • 28
  • 261
  • 374
  • 1
    Stop trying to do this. See [Is it legal to have a cross-process parent/child or owner/owned window relationship?](http://blogs.msdn.com/b/oldnewthing/archive/2013/04/12/10410454.aspx) for why it's so bad. "it is technically legal. It is also technically legal to juggle chainsaws ... near-impossible to manage if one or both of the windows involved is unaware that it is participating in a cross-process window tree" – Damien_The_Unbeliever Jul 20 '15 at 06:58
  • 1
    @Damien_The_Unbeliever sage advice. How do programs like Lync/"Skype-for-Business" implement their overlays then? – Dai Jul 20 '15 at 07:02

0 Answers0