zoukankan      html  css  js  c++  java
  • 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 = @"XXXFilesDebugVsTest.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/】

  • 相关阅读:
    2019 Java 第四周总结
    2019第三周总结
    Java 第二周总结
    2019春第十二周作业
    Day3
    Day3
    Day3
    Day3
    Day2
    Day2
  • 原文地址:https://www.cnblogs.com/CUIT-DX037/p/7170660.html
Copyright © 2011-2022 走看看