C#窗體內嵌外部程序(cmd.exe)的顯示【轉載】

[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);

        }

本文轉自:請點擊spa

相關文章
相關標籤/搜索