如题,谢谢!

解决方案 »

  1.   

    用Windows.SetParent,最近很多人问这个问题
      

  2.   

    我用了网上看的这段程序
    var
      Hand: integer;
    begin
      Hand:=FindWindow('notepad',nil);
      if Hand=0 then
       begin
       ShellExecute(self.Panel1.Handle ,'','c:\windows\notepad.exe',nil,nil,sw_show);
       Sleep(100);
       Hand:=FindWindow('notepad',nil);
      end;
      Windows.SetParent(Hand, self.Panel1.Handle);
    调用notepad时,可以在panel上显示,但是换成其他的外部程序就不行,这是怎么回事啊?
      

  3.   

    Hand:=FindWindow('notepad',nil);
    这句查找窗体的句柄是针对记事本这个程序的。notepad是记事本的类名,后一个参数是窗体的标题。你可以用SPY++这个工具来查看其它外部程序的类名和标题。
      

  4.   

    谢谢楼上的,我试了一下可行。但是我要用到的那个外部程序,是一个MDIClient型的,好像不行,有没有解决方法?
      

  5.   

    试了一下,MDIClient的效果不理想,一最大化就会消失,原来外部程序的主窗体也消失,应该还要设置点什么。
      

  6.   

    谢谢。我将主程序设置为MDIForm,但是也没什么用阿。
      

  7.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Button10: TButton;
        Panel1: TPanel;
        procedure Button10Click(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      h:HWND;
    implementation
    uses clipbrd;
    {$R *.DFM}//把计算器作为自己程序的子窗口
    procedure TForm1.Button10Click(Sender: TObject);
    begin
      WinExec('calc.exe',SW_SHOW);
      h := FindWindow('SciCalc',nil);
      Windows.SetParent(h,Panel1.Handle);
      //SetWindowLong (h, GWL_STYLE, GetWindowLong (h, GWL_STYLE) AND NOT WS_CAPTION);
      SetWindowPos(h,HWND_BOTTOM,-2,-22,600,200,0);  //设定位置
      //EnableWindow(h,false);
    end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      PostMessage(h, WM_CLOSE, 0, 0);
    end;end.