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