如何从一个DLL中显示一个MDI子窗体?(300分)

  • 主题发起人 主题发起人 程云
  • 开始时间 开始时间

程云

Unregistered / Unconfirmed
GUEST, unregistred user!
如何从一个DLL中显示一个MDI子窗体?

在一个DLL中写如下程序:
Form设为fsMDIChild

unit DLLFrm;

interface

uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, Grids, Calendar;

type

TDLLForm = class(TForm)
calDllCalendar: TCalendar;
end;

function ShowCalendar(AHandle: THandle; ACaption: String): Longint; stdCall;
procedure CloseCalendar(AFormRef: Longint); stdcall;


implementation
{$R *.DFM}

function ShowCalendar(AHandle: THandle; ACaption: String): Longint;
var
DLLForm: TDllForm;
begin
Application.Handle := AHandle;
DLLForm := TDLLForm.Create(Application); { show }
Result := Longint(DLLForm);
DLLForm.Caption := ACaption;
end;

procedure CloseCalendar(AFormRef: Longint);
begin
if AFormRef > 0 then
TDLLForm(AFormRef).Release;
end;

end.


在主程序中写如下方法来调用这个DLL中的窗体
主Form设为fsMDIForm

unit MainFfm;

interface

uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;

type

TMainForm = class(TForm)
btnShowCalendar: TButton;
btnCloseCalendar: TButton;
procedure btnShowCalendarClick(Sender: TObject);
procedure btnCloseCalendarClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
FFormRef: TForm;
end;

var
MainForm: TMainForm;

function ShowCalendar(AHandle: THandle; ACaption: String): Longint; StdCall;
external 'CALENDARMLLIB.DLL';

procedure CloseCalendar(AFormRef: Longint); stdcall;
external 'CALENDARMLLIB.DLL';

implementation

{$R *.DFM}

procedure TMainForm.btnShowCalendarClick(Sender: TObject);
begin
if not Assigned(FFormRef) then
FFormRef := TForm(ShowCalendar(Application.Handle, Caption));
end;

procedure TMainForm.btnCloseCalendarClick(Sender: TObject);
begin
if Assigned(FFormRef) then
begin
CloseCalendar(Longint(FFormRef));
FFormRef := nil;
end;
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
FFormRef := nil;
end;

end.



只是不知何故,就在创建子窗体时出错,说是没有发现主MDI窗体。
可我明明已设了。

可能是这个子窗体无法……
 
看我的帖子《DELPHI制作DLL全集》。唉,我发了这么多遍,就是没人愿意查一下。
 
我也想知道啊,who can 告诉我?
 
我看到了,是这个帖子吧,多谢了。

http://www.delphibbs.com/delphibbs/dispq.asp?lid=534762

我已试通了,

我的程序改为如下

function ShowForm(FHandle: THandle; mainform: TForm):LongInt;StdCall;
var
ptr:PLongInt;
begin
OHandle:=FHandle;
ptr:=@(Application.MainForm);
ptr^:=LongInt(mainForm);
DllForm:=TDllForm.Create(mainform);
Result:=LongInt(DllForm);
end;

FHandle这个参数,是为了近制与此有关的同生对象用的,
 
再次多谢这位仁兄了。
些许分数,不成敬意。
 
后退
顶部