c#的winform调用外部 exe 作为子窗体,那位达达给个源代码,谢谢

解决方案 »

  1.   

    Public Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
      

  2.   

            这样很容易出错,出错别怪我
            using System.Runtime.InteropServices;        [DllImport("user32.dll")]
            static extern int FindWindow(string lpClassName, string lpWindowName);        [DllImport("user32.dll")]
            static extern int SetParent(int hWndChild, int hWndNewParent);        private void button1_Click(object sender, EventArgs e)
            {
                System.Diagnostics.Process.Start("calc.exe");
                System.Threading.Thread.Sleep(300);            SetParent(FindWindow(null, "计算器"), this.Handle.ToInt32());
            }
      

  3.   

     System.Diagnostics.Process p = System.Diagnostics.Process.Start(@"Calc");
                p.WaitForInputIdle();            SetParent(p.MainWindowHandle, this.Handle);
                ShowWindowAsync(p.MainWindowHandle, 3);
    这段程序似乎可以吧其他程序调用进主程序,但是除了calc,notepad这种程序外好像其他都不行,不知道这两个windows
    api怎么用
      

  4.   

    但是除了calc,notepad这种程序外好像其他都不行,不知道为什么
      

  5.   

    可能是别的程序有多个窗口,p.MainWindowHandle获得的句柄不对吧
    那你用FindWindow试试
      

  6.   


    可能是因为路径的缘故吧,看你的代码里Calc用的似乎是相对路径使用其他程序时写入绝对路径试试
      

  7.   

    运行exe用这个:            System.Diagnostics.Process.Start(@"C:\1.exe");
      

  8.   

    记得此板块中有好多人问过好多次,都没有太好的sln.
      

  9.   

    你把程序放在bin debug 文件夹下.
    System.Diagnostics.Process.Satrt("xx.exe");试试