2

我需要在我的 WPF 窗口中托管 win32 窗口,但我需要它们像用户控件一样工作。其他控件需要能够出现在它们之上,并且它们应该能够被放入选项卡控件等中。这样的事情可能吗?

4

4 回答 4

3

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.

于 2013-01-28T21:59:14.407 回答
1

在我看来是做不到的。

您可以尝试使用 winform 用户控件并将其放在 windowsformhost 控件中,但即使在这种情况下,windowsformhost 它始终位于顶部,并且您不能将其他控件放在它上面。其原因被称为空域问题。

于 2013-01-28T21:58:22.597 回答
0

不,您最多可以隐藏本机窗口并转发图形以及它与 WPF 控件(ala 远程桌面)之间的用户交互。但这实际上不会在您的 WPF 窗口上托管本机窗口(如果本机窗口与其父窗口交互,它将被破坏)。

这是因为所有 WPF 内容都在单个 Win32 窗口中,在 Win32 z 顺序中的单个插槽中,因此其他 WPF 内容不能同时位于此其他子控件的下方和上方。

于 2013-01-28T21:58:43.720 回答
0

当然,可以在 WPF API 中嵌入 Win32 窗口。例如:

如何将另一个应用程序的窗口嵌入到我们的 WPF 窗口中作为用户控件?

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);

问:您的 WPF UI 会“意识到”这个(低级)窗口吗?
答:不-当然不是:)

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...

于 2013-01-28T21:58:57.573 回答