|
首先,可能例子做得有点不这么好。但是确实是实现了,请毋怀疑我用“父窗体调用子窗体"的那种代码来忽悠你看效果图
1.引用 win api
[DllImport("User32.dll ", EntryPoint = "SetParent")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll ", EntryPoint = "ShowWindow")]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
2.代码调用api就可以了
Process p = new Process();
p.StartInfo.FileName = "cmd.exe ";
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;//加上这句效果更好
p.Start();
System.Threading.Thread.Sleep(100);//加上,100如果效果没有就继续加大
SetParent(p.MainWindowHandle, this.Handle); //为要显示外部程序的容器,这里需要注意一些
ShowWindow(p.MainWindowHandle, 3);
代码就这么简单,整理得不好。不喜勿喷,谢谢!
|
|