你可以試試這個(菜單文件名不具有擴展名爲.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()是最低要求。 –