请问各位大鸟
我怎么样才可以在
主程序的一个form的panel上显示dll文件中的 form啊!
顶者有分啊!

解决方案 »

  1.   

    我没有用过Dll中的窗体,但我想和普通窗体也差不多吧!你设置它的Parent属性不可以吗?
    比如Form2.Parent:=Form1.Panel1;
      

  2.   

    library Project2;uses
      SysUtils,
      Classes,
      Forms,
      WIndows;var
      FhPrevApp: HWND:
    {$R *.RES}
    procedure DllHandler(AReason: Longint);
    begin
      case AReason of
        DLL_PROCESS_ATTACH: FhPrevApp := Application.Handle;
        DLL_PROCESS_DETACH: Application.Handle := FhPrevApp;
      end;
    end;procedure CreateChild(AhApp: HWND; AhParent: HWND; AIndex: Integer); stdcall;
    var
      f: TForm;
    begin
      Application.Handle := AhApp;
      case AIndex of
      begin
        0:
          begin
            f := TForm1.Create(Application);
            SetParent(f, AhParent);
            f.Show;
          end;
        1:
          begin
            f := TForm2.Create(Application);
            SetParent(f.Handle, AhParent);
            f.Show;
          end;
      end;
    end;exports
      CreateChild;begin
      DllProc := @DllHanlder;
    end.
      

  3.   

    type
      TCreateChild = procedure(AhApp: HWND; AhParent: HWND); stdcall;var
      Form1: TForm1;
      FPCreateChild :TCreateChild;
      gh:THandle;
    .......procedure TForm1.Button2Click(Sender: TObject);
    begin
      gh := LoadLibrary('project2.dll');
      FPCreateChild := GetProcAddress(gh,'CreateChild');
      FPCreateChild(Application.Handle, Panel1.Handle);
      FreeLibrary(gh);
    end;