我想把网上下的别人做好的软件作为我程序的子界面来用,请问大家有什么办法让调用的这个exe文件不脱离我的主窗体,并受我主窗体控制,比如,我主窗体最小化的时候我调用的这个exe软件也最小化,我的主窗体退出的话他们也退出。
大家要是做过这方面的东西,给个提示,谢谢了!有演示类型的代码更好!

解决方案 »

  1.   

     [DllImport("user32", EntryPoint = "SetParent", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
            public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
            [DllImport("user32", EntryPoint = "FindWindowA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
            public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
            [DllImport("user32.dll", EntryPoint = "SendMessageA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
            private static extern int SendMessage(int hwnd, int wMsg, int wParam, int lParam);
            [DllImport("shell32.dll", EntryPoint = "ShellExecuteA", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
            private static extern int ShellExecute(int hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);
            private const int WM_SYSCOMMAND = 0x112;
            private const int SC_MAXIMIZE = 0xF030;
            private const int SC_MINIMIZE = 0xF020;
            private const int SC_RESTORE = 0xF120;
            public const int SW_HIDE = 0;
            public const int SW_SHOW = 5;
            [DllImport("user32.dll ", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
            private static extern int ShowWindow(int hwnd, int nCmdShow);
      ShellExecute(this.panel1.Handle.ToInt32(), "open", @"c:\\windows\\system32\\cmd.exe", null, ".", SW_HIDE);  // 让cmd.exe运行在PANEL里
                IntPtr h = FindWindow(null, "c:\\windows\\system32\\cmd.exe");
      var frm = (Control)Form.FromHandle(h);
     SetParent(h, this.panel1.Handle); //嵌套到panel1内  
                SendMessage(h.ToInt32(), WM_SYSCOMMAND, SC_MAXIMIZE, 0);
                ShowWindow(h.ToInt32(), SW_SHOW);
      

  2.   

    楼上的方法好像只能调用CMD和NotePad这类的程序
    要是已经做好的带窗体的软件的话
    就不行了
    大家有没有能够实现的高人
    分享下方法