C# 如何将流程的第二个窗口移动到面板中?

C# 如何将流程的第二个窗口移动到面板中?,c#,process,C#,Process,我试图将Windows窗体应用程序的输出放入另一个应用程序中的面板(panel2)。这是我目前的代码: [DllImport("user32.dll")] static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); [DllImport("user32.dll")] static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); [

我试图将Windows窗体应用程序的输出放入另一个应用程序中的面板(panel2)。这是我目前的代码:

[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll")]
static extern bool MoveWindow(IntPtr Handle, int x, int y, int w, int h, bool repaint);

pcproc = Process.Start(@"C:\\Program Files (x86)\Application\app.exe");
pcproc.WaitForInputIdle();
SetParent(pcproc.MainWindowHandle, panel2.Handle);
MoveWindow(pcproc.MainWindowHandle, panel2.Location.X, panel2.Location.Y, panel2.Width, panel2.Height,true);

现在不幸的是,应用程序启动了两个窗口(两个窗口都没有窗口标题,不幸的是我无法更改),其中第二个窗口启动了,这是我想放在面板中的窗口。上面的代码只在面板中放置了第一个窗口,这是我不想要的。那么,如何将启动的第二个窗口移动到面板中呢?

这里的所有应用程序都是您自己的,并且可以修改吗?如果不是这样,你将走上一条非常黑暗的道路,很可能不会有好的结果。程序的编写倾向于假设他们自己的顶级窗口将保持顶级,而不是突然有另一个窗口宣布他们是它的父窗口。选择引述:“是的,从技术上讲这是合法的。玩电锯从技术上讲也是合法的。”我意识到风险,但我仍然想继续这样做。