0

我有两个应用程序。一个是 WinForms 应用程序(又名 Parent),另一个是 WPF 应用程序(Child)。

Child 可以像 Parent 一样独立运行。我正在研究 Child 的功能,使其在 Parent 中的行为类似于 UserControl,但仍作为单独的进程运行。

我已经成功调用 SetParent 并让 Forms.UserControl 处理 Child 的大小和位置。

//owningHandle is the handle of the winform control that Child resides in.
//owner is the user control
//addinHandle is the handle of the Child window

SetParent(addinHandle, owningHandle);
SetWindowLongPtr(addinHandle, GWL_STYLE, style);
SetWindowPos(addinHandle,
             IntPtr.Zero,
             owner.Left, owner.Top,
             (int) owner.Width, (int)owner.Height,
             SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE);

现在我们希望能够从父进程 UnSetParent 子进程。我已经读过我需要做的“所有”事情就是调用 SetParent,父参数为 0(IntPtr.Zero)。

//I store the original Window style in _originalStyle before calling the SetParent logic above. This way we can get the proper Windows border around the application
uint newStyle = (uint)_originalStyle;
newStyle = (newStyle | (uint)WindowStyles.WS_POPUP) & (uint)(~WindowStyles.WS_CHILD);
SetWindowLongPtr(addinHandle, GWL_STYLE, newStyle);
SetParent(addinHandle, IntPtr.Zero);

但是,我注意到在大多数情况下,我的 Child 应用程序无法以任何方式被点击。没有任何 UI 组件响应单击,包括窗口上的最小化、恢复、关闭按钮。如果我单击任何位置,我会收到 Windows 哔声。我可以附加一个调试器并查看应用程序中运行的任何计时器仍在运行。

分离 WPF 应用程序时需要采取一些步骤吗?

4

0 回答 0