通過DLL中的導出函數CallDLLFormByTag調出DLL中窗體來,但不知如何設置使其變成主窗體的MDI子窗體,
procedure CallDLLFormByTag(a: integer;MainForm: TForm);
begin
try
case a of
1:
begin
frmCac := TfrmCac.Create(nil);
frmCac.ParentWindow := MainForm.Handle;
frmCac.Show;
end;
2:
begin
Form1 := TForm1.Create(nil);
Form1.ParentWindow := MainForm.Handle;
Form1.Show;
end;
else
begin
//
end;
end;
finally
//
end;
end;
求解
procedure CallDLLFormByTag(a: integer;MainForm: TForm);
begin
try
case a of
1:
begin
frmCac := TfrmCac.Create(nil);
frmCac.ParentWindow := MainForm.Handle;
frmCac.Show;
end;
2:
begin
Form1 := TForm1.Create(nil);
Form1.ParentWindow := MainForm.Handle;
Form1.Show;
end;
else
begin
//
end;
end;
finally
//
end;
end;
求解
Form1 := TForm1.Create(nil);
//我喜欢这样调用:
//Application.CreateForm(TForm1, Form1);Form1.FormStyle:=fsMDIChild;
Form1.ParentWindow := MainForm.Handle;
Form1.Show;
什麼意思 啊?能不能說明一下?
begin
Application.Handle:=aHandle;
try
case a of
1:
begin
frmCac := TfrmCac.Create(Application);
frmCac.ParentWindow := aHandle;
frmCac.Show;
end;
2:
begin
Form1 := TForm1.Create(Application);
Form1.ParentWindow :=aHandle;
Form1.Show;
end;
在mainform掉用的时候,把mainform.handel出入到ahandle参数看看,
frmCac.FormStyle:=fsMDIChild;
是可以的, 但是在調用DLL的窗體就會出錯:no MDI forms are currently actived
unit ExportUnit;
interface
implementation
uses
SysUtils, Classes, Forms,
test , test2 ;procedure ShowDLLMDIForm(a: integer;AHandel : THandle);
begin
Form1 := TForm1.Create(nil);
Form1.FormStyle:=fsMDIChild;
Form1.ParentWindow :=AHandel;
Form1.Show;end;exports ShowDLLMDIForm;
//-----------------
end.
begin
Application.Handle:=aHandle;
try
case a of
1:
begin
frmCac := TfrmCac.CreatePanerted(Application.MainForm.Handle);
frmCac.Show;
end;
……
end;
在看看吧,同志,,,
InvokeDLLForm = function(App: TApplication; Scr: TScreen): TForm;procedure TfrmMain.mi_inDLLClick(Sender: TObject);
var
DLLHandle: THandle;
DLLSub: InvokeDLLForm;begin
DLLHandle := LoadLibrary('prjDLL.dll');
if DLLHandle <> 0 then
begin
@DLLSub := GetProcAddress(DLLHandle, 'CreateDLLForm');
if Assigned(DLLSub) then
begin
DLLForm := DLLSub(Application, Screen);
end;
end;
end;--Dll中的Dpr文件---------------------------
library prjDLL;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils,
Forms,
Windows,
Messages,
Classes,
DLLFormUnit in 'DLLFormUnit.pas' {frmDLLForm},
AboutUnit in 'AboutUnit.pas' {frmAbout};{$R *.res}var
DLLApp: TApplication;
DLLScr: TScreen;
function CreateDLLForm(App: TApplication; Scr: TScreen):TForm;
var
ptr:PLongInt;
begin
Application := App;
Screen := Scr;
Application.CreateForm(TfrmDLLForm, frmDLLForm);
Application.CreateForm(TfrmAbout, frmAbout);
result:=frmDLLForm;
end;procedure ExitDLL(Reason: Integer);
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApp;
Screen := DLLScr;
end;
end;
exports
CreateDLLForm;begin
DLLApp := Application;
DLLScr := Screen;
DLLProc := @ExitDLL;end.------------------------------------网上有完整的例子,可以去搜一下。
procedure ShowDLLMDIForm(ParentApplication: TApplication; ParentForm: TForm);export; stdcall;
begin
Application:=ParentApplication;
Form1:=TForm1.Create(ParentForm);
Form1.Show;
end;
//-----------------
library dllFinanceRep;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
SysUtils, Classes, Windows, Messages, Forms,
test in 'test.pas' {Form1},
test2 in 'test2.pas' {Form2},
ExportUnit in 'ExportUnit.pas';
var
DllApplication: TApplication;
procedure DLLUnloadProc(Reason: Integer); register;
begin
if Reason = DLL_PROCESS_DETACH
then Application:=DllApplication;
end;{$R *.res}
begin
DllApplication:=Application;
DLLProc := @DLLUnloadProc;
end.