5,388
社区成员
发帖
与我相关
我的任务
分享
///////////////////////////DLL项目
library FormInDll;
uses
forms,
Windows,
SysUtils,
Classes,
Unit1 in 'Unit1.pas' {Form1};
{$R *.res}
function GetDLLForm(AParent:HWND) : Integer;
begin
Result := -1;
try
with TForm1.Create(Application) do
begin
ParentWindow := AParent;
Show;
end;
except on E: Exception do
Result := 0;
end;
end;
exports
GetDLLForm;
begin
end.
///////////////////////////Dll窗体, Create事件
procedure TForm1.FormCreate(Sender: TObject);
begin
BorderStyle := bsNone;
Align := alClient;
end;
///////////////////////////静态调用Dll窗体
//静态调用 Begin
function GetDLLForm(AParent:HWND) : Integer; external 'FormInDll.dll';
procedure TForm14.btn3Click(Sender: TObject);
var
n : integer;
begin
n := GetDLLForm(pnl2.Handle);
n := GetDLLForm(pnl3.Handle);
end;
//静态调用 End
procedure TformMain.WMSize(var Message: TWMSize);
var
h, h2: THandle;
rc: TRect;
begin
inherited;
h := FindWindowEx(Handle, 0, 'TPanel', nil);
if h = 0 then
exit;
h := FindWindowEx(h, 0, 'TPanel', nil);
if h = 0 then
exit;
h := FindWindowEx(h, 0, 'TfDllform', 'fDllform');
if h = 0 then
exit;
h2 := FindWindowEx(h, 0, 'TfmMain', nil);
if h2 = 0 then
exit;
GetWindowRect(PanelParent.Handle, rc);
SetWindowPos(h, HWND_TOP, 0, 0, rc.Right - rc.Left, rc.Bottom - rc.Top, SWP_NOACTIVATE);
SetWindowPos(h2, HWND_TOP, 0, 0, rc.Right - rc.Left, rc.Bottom - rc.Top, SWP_NOACTIVATE);
end;