如何在dll中创建窗口?我想在dll被调用的时候立刻出现一个窗口,该窗口是包含在dll中的

解决方案 »

  1.   

    建立dll文件,然后在其中添加窗体,窗体设计随便,
    例如
    unit aboutunit;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ExtCtrls;type
      Taboutform = class(TForm)
        Panel1: TPanel;
        Bevel1: TBevel;
        procedure FormCreate(Sender: TObject);
        procedure FormShow(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      aboutform: Taboutform;
      
    function showform(title:string;version:string):boolean;stdcall;implementation{$R *.DFM}
    function showform(title:string;version:string):boolean;
    var
      aboutform:Taboutform;
    begin
      ......
      result:=false;
      aboutform:=taboutform.Create(application);
      aboutform.show;
      ......
    end;
    还可以写其他语句然后编译,在调用时用那个函数就可以了
      

  2.   

    在dll里用函数:
    Function Openform1(Handle:THandle;Parent:TWinControl;):Longint;
    begin
      Result:=-1;
      if Not Assigned(form1) then
      begin
      try
       Application.Handle:=Handle;
       form1:=form1.Create(Application);
       Windows.SetParent(form1.Handle,Parent.Handle);
       form1.Show;
       Result:=Longint(form1);
       except
       end;
      end
    end;exports
      Openform1;
    begin
    end.相应的在exe里也调用该函数,就ok了,exe里的代码你应该会写吧。
    我一直用这种方法,肯定没问题的。
      

  3.   

    http://expert.csdn.net/Expert/topic/2505/2505608.xml?temp=1.588076E-02
      

  4.   

    问一下,2楼的是unit,不是dll吧?
    3楼的,那个form1的类的申明在哪里?
      

  5.   

    恩,偶搞懂了
    在library的proj里增加一个unit包含form1
    然后uses unit1
    对吧?
      

  6.   

    但是,当主程序关闭时总报错"应用程序发生异常(0x0eedfade)"。怎样释放dll里面的Form?