您的位置:首页 > 编程语言 > C#

C#窗体内嵌外部程序(cmd.exe)的显示

2012-04-07 10:40 246 查看
[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);

private void button3_Click(object sender, EventArgs e)

{

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, panel1.Handle); //panel1.Handle为要显示外部程序的容器

ShowWindow(p.MainWindowHandle, 3);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: