简体   繁体   中英

Embed win32 window in WPF window, without HwndHost

I need to host win32 windows in my WPF window, but I need them to act like user controls. Other controls need to be able to appear on top of them, and they should be able to be put into tab controls and such. Is such a thing possible?

Not directly. Airspace issues apply here, which prevents you from using the HWND (Win32) window directly like you would other content.

There are various workarounds, such as this AirspaceOverlay control . These function by creating a separate WPF Window without chrome, and "overlaying" it on top of your HWND, moving it as needed.

In my opinion it can't be done.

You could try to do it with a winform usercontrol and putting it in a windowsformhost control, but even in this this case the windowsformhost it's always on the top, and you can't put other controls over it. The reason for this is known as the AirSpace Issue.

No. At best you can have the native window be hidden and forward graphics and user interaction between it and a WPF control (ala Remote Desktop). But this won't actually be hosting the native window on your WPF window (if the native window interacts with its parent it will be broken).

This is because all WPF content is in a single Win32 window, in a single slot in the Win32 z-order, so other WPF content can't be both below and above this other child control.

Sure, it's possible to embed a Win32 window in a WPF API. For example:

How to embed Window from another application in our WPF window as user control?

Process p = Process.Start(@"application.exe");

p.WaitForInputIdle();
IntPtr appWin = p.MainWindowHandle;

SetParent(appWin, parent);
SetWindowLong(appWin, GWL_STYLE, WS_VISIBLE);
System.Threading.Thread.Sleep(100);
MoveWindow(appWin, 0, 0, ClientRectangle.Width, ClientRectangle.Height, true);

Q: Will your WPF UI be "aware" of this (low-level) Window?
A: No - of course not :)

Q: What do you mean by "without hWndHost"?
If you mean you don't want to use code like the above ... you're probably SOL . At least using WPF...

'Hope that's helps ... at least a little bit...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM