Reputation: 5260
My WPF app is called by a C program (unmanaged). I want to make the WPF app stay on the screen where the calling app is. I have dual monitor.
So I want to make my WPF form WindowStartupLocation="CenterOwner" and set the owner to the calling app.
I can get the calling app via
Process.GetProcessById(CallingProcessID)
What is the next step to set WPF window Owner to the calling app?
Update: The purpose of the question is to make WPF windows all stay on the screen where the calling program resides.
Upvotes: 0
Views: 123
Reputation: 15217
Assuming you have a window handle of your unmanaged application (HWND), you can use the WindowInteropHelper
to set this HWND as your WPF window's parent.
WindowInteropHelper wih = new WindowInteropHelper(myWpfWindow);
wih.Owner = unmanagedOwnerHwnd;
The Owner
property is of IntPtr
type, so this should solve your issue.
Upvotes: 2