C# 將外部exe程序 嵌入到自己的窗體界面


將別人開發的exe程序,放到自己的窗體里面來運行。

1.基本功能實現

    首先,在自己的窗體后面加上代碼:

        [DllImport("User32.dll", EntryPoint = "SetParent")]
        private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        [DllImport("user32.dll", EntryPoint = "ShowWindow")]
        private static extern int ShowWindow(IntPtr hwnd, int nCmdShow);

    然后在需要的地方,加上代碼:

            string fexePath = @"XXX\Files\Debug\VsTest.exe"; // 外部exe位置

            Process p = new Process();
            p.StartInfo.FileName = fexePath;
            p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
            p.Start();

            while (p.MainWindowHandle.ToInt32() == 0)
            {
                System.Threading.Thread.Sleep(100);
            }
            SetParent(p.MainWindowHandle, this.Handle);
            ShowWindow(p.MainWindowHandle, (int)ProcessWindowStyle.Maximized);

 即可:

 

 

 

 

【http://www.cnblogs.com/CUIT-DX037/】


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM