https://blog.csdn.net/opensource_liu/article/details/48002255
1.定義窗體
- unit UDllForm;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
-
- type
- TDllForm = class(TForm)
- btn1: TButton;
- procedure btn1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- DllForm: TDllForm;
- procedure ShowDllFormInPanel(Parent:THandle);stdcall;
- procedure ShowDllForm;stdcall;
- implementation
-
- procedure ShowDllFormInPanel(Parent:THandle);stdcall;
- begin
- Application.handle:=parent;
- if DllForm = nil then
- DllForm:= TDllForm.Create(Application);
- DllForm.ParentWindow:=Parent;//將容器設置為父窗口
- DllForm.Show;
- end;
-
- procedure ShowDllForm;stdcall;
- begin
- if DllForm = nil then
- DllForm:= TDllForm.Create(Application);
- DllForm.Show;
- end;
-
- {$R *.dfm}
-
- procedure TDllForm.btn1Click(Sender: TObject);
- begin
- ShowMessage('HELLO');
- end;
-
- end.
2.定義dll
- library Formindll;
-
- uses
- SysUtils,
- Classes,
- UDllForm in 'UDllForm.pas' {DllForm};
-
- {$R *.res}
- exports
- ShowDllFormInPanel,
- ShowDllForm;
- begin
- end.
3.dll窗體調用
注意:dll窗體不能直接放在父窗體里面 ,這里可以使用panel作為父窗體 對應過(guò)程ShowDllFormInPanel
dll窗體不放在父窗體 則直接使用ShowDllForm 過(guò)程,想一個(gè)對話(huà)框的形式
- unit Unit1;
-
- interface
-
- uses
- SysUtils,Classes,Forms,Windows,Messages, Controls, StdCtrls, ExtCtrls;
-
- type
- TForm1 = class(TForm)
- btn1: TButton;
- pnl1: TPanel;
- btn2: TButton;
- procedure btn1Click(Sender: TObject);
- procedure btn2Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
- procedure ShowDllFormInPanel(Parent:THandle);stdcall; external 'E:\test7\formindll.dll';
- procedure ShowDllForm; stdcall; external 'E:\test7\formindll.dll';
- implementation
-
- {$R *.dfm}
-
- procedure TForm1.btn1Click(Sender: TObject);
- begin
- ShowDllFormInPanel(pnl1.Handle);
- end;
-
- procedure TForm1.btn2Click(Sender: TObject);
- begin
- ShowDllForm;
- end;
-
- end.
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請
點(diǎn)擊舉報。