我想在dll中创建一个窗体,把她显示在调用他的主窗口的一个panel中
该怎么做?!!!

解决方案 »

  1.   

    把你的dll中建的Form1.show export出去就行了。
      

  2.   

    DLLApp.Handle := MainApp.Handle;
      

  3.   

    procedure CreateChild(AApplication: TApplication; AMDIForm: TForm; AFormClass: TFormClass); export; stdcall;
    begin
       Application := AApplication;
       with AFormClass.Create(AMDIForm) do Show;
    end;
      

  4.   

    还要怎么详细自己,  总不要我全部写出来吧
    上面是Dll中的方法主程序调用
    CreateChild(Application, MainForm, TForm1);
    CreateChild(Application, MainForm, TForm2);
      

  5.   

    不好意思,我指的是你的第一次回复!!
    创建MDI子窗体我用其他的方法实现的。
    对你的方法有一点疑问:
      AFormClass: TFormClass
                  ~~~~~~~~~~~是要从DLL中导出的嘛?另外,我还是不知道怎么把一个DLL中的窗口显示在主窗口(都是普通窗口)的Panel中!
      

  6.   

    那你就换一种方式,  两边约定一下,  我写了个例子供你参考没有调试你自己看看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, AhParent);
            f.Show;
          end;
      end;
    end;exports
      CreateChild;begin
      @DllProc := DllHanlder;
    end.
      

  7.   

    问题解决,非常谢谢!!
    有几处笔误:
      SetParent(f, AhParent);  应为:SetParent(f.Handle, AhParent);
      @DllProc := DllHanlder;  应为:DllProc := @DllHandler;给分!!