我试图在Visual C#2010 - Windows窗体应用程序中启动外部进程.目标是将该过程作为隐藏窗口启动,并在以后取消隐藏窗口.
我已经更新了我的进度:
//Initialization
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dll")]
private static extern bool EnableWindow(IntPtr hwnd, bool enable);
[DllImport("user32.dll")]
private static extern bool MoveWindow(IntPtr handle, int x, int y, int width,
int height, bool redraw);
SW_SHOW = 5;
Run Code Online (Sandbox Code Playgroud)
以下内容放在我的主要功能中:
ProcessStartInfo info = new ProcessStartInfo("process.exe");
info.WindowStyle = ProcessWindowStyle.Hidden;
Process p = Process.Start(info);
p.WaitForInputIdle();
IntPtr HWND = p.MainWindowHandle;
System.Threading.Thread.Sleep(1000);
ShowWindow(HWND, SW_SHOW);
EnableWindow(HWND, true);
MoveWindow(HWND, 0, 0, 640, 480, true);
Run Code Online (Sandbox Code Playgroud)
但是,因为窗口被启动为"隐藏" p.MainWindowHandle = 0.我无法成功显示窗口.我也尝试HWND = …