Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Win32 window as owner of WPF window?

Tags:

wpf

winapi

owner

I want to use WPF windows in a legacy win32 application. I'd like to behave them in a similar way, like the WPF window always being displayed on top of the win32 window.

For this I'd like to set the owner of the WPF window to the win32 windows, but I got no idea how to achieve this.

Any help here?

Since the answer is hidden behind some link, here the code that did the trick:

System::Windows::Interop::WindowInteropHelper^ helper = gcnew System::Windows::Interop::WindowInteropHelper(myWpfChildWindow);
helper->Owner = (System::IntPtr)myMainWindowHWND;
like image 363
Sam Avatar asked Apr 08 '10 10:04

Sam


1 Answers

This article shows how to get the handles for both as well as how to make the WPF window become a transparent overlay for the win32 window.

http://dedjo.blogspot.com/2007/04/transparent-wpf-control-over-unmanaged.html

This article uses a WindowInteropHelper to accomplish similar functionality.

http://blogs.msdn.com/wpfsdk/archive/2007/04/03/centering-wpf-windows-with-wpf-and-non-wpf-owner-windows.aspx

MSDN page on WindowInteropHelper:

http://msdn.microsoft.com/en-us/library/system.windows.interop.windowinterophelper.aspx

Hope that helps, Ed

like image 128
Ed Gonzalez Avatar answered Sep 21 '22 18:09

Ed Gonzalez