我的环境是Winforms .NET 4.0。我正在运行两个例程:SetParent&发信息。例程定义如下:
[DllImport("user32.dll")]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, uint wParam, uint lParam);
例程用于强制外部进程的窗口进入Winforms选项卡。这是我们使用的代码:
SetParent(procSlic3r.MainWindowHandle, Main.main.TPSlic3r.Handle);
SendMessage(procSlic3r.MainWindowHandle, 274, 61488, 0);//panelSlic3r
setupwindow("Slic3r", Main.main.TPSlic3r);
public void setupwindow(string processWindow, Control ParentControl)
{
IntPtr hwndChild = FindWindow(null, processWindow);
if (FindWindow(null, processWindow).ToInt32() < 1)
{
return;//no process by this name found
}
SetParent(hwndChild, ParentControl.Handle);
Point PZero = new Point(0, 0);
SetWindowPos(hwndChild, (IntPtr)(-1), ParentControl.PointToScreen(PZero).X, ParentControl.PointToScreen(PZero).Y,
ParentControl.Width, ParentControl.Height, SWP_ASYNCWINDOWPOS + SWP_FRAMECHANGED + SWP_SHOWWINDOW);//+SWP_NOOWNERZORDER);
SendMessage(hwndChild, 274, 61488, 0);//tell them to expand please
}
此代码在32位Windows 8.1 / Windows 10上运行良好,但它在64位Windows 10中无效。相反,子窗口消失,标签保持空白。
有谁知道如何解决这个问题?
提前致谢!