你可以试试这个(菜单文件名不具有扩展名为.exe来运行exe )
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
在功能
然后
var proc = new Process();
proc.StartInfo.FileName = "Menu.exe";
proc.StartInfo.Arguments = "/c echo hello user ^<!^> && pause",
proc.Start();
SetParent(proc.MainWindowHandle, this.panel2.Handle);
更新
using System.Runtime.InteropServices;
using System.Threading;
[DllImport("user32.dll", SetLastError = true)]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
然后
var proc = new Process();
proc.StartInfo.FileName = "Menu.exe";
proc.Start();
IntPtr ptr = IntPtr.Zero;
while ((ptr = proc.MainWindowHandle) == IntPtr.Zero) ;
SetParent(proc.MainWindowHandle, trackerPanel.Handle);
MoveWindow(proc.MainWindowHandle, 0, 0, this.Width - 90, this.Height, true);
参考this
您正在尝试设置时光倒流到1990年,回来的时候,这不是一个问题。你试图更好地运行的程序是90年代的程序。就像记事本一样,先用那个试一下。非常明显的错误是试图在面板中放置一个最小化窗口,而不是等待进程创建其主窗口句柄。调用Process.WaitForInputIdle()是最低要求。 –