我创建了两个Delphi 6应用程序:主机应用程序和DLL中的框架。除了按照ALClient样式的TabSheet客户端大小之外,一切正常:框架根本没有调整大小。我认为用ShowWindow
调用SW_SHOWMAXIMIZED
会完成任务,但它只会调整一次框架的大小。
这是主机应用程序的主要形式:
unit Form1Unit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
procedure TabSheet1Show(Sender: TObject);
procedure TabSheet2Show(Sender: TObject);
procedure TabSheet3Show(Sender: TObject);
private
_dllHandle1: LongWord;
function getDllHandle1(): LongWord;
property DllHandle1: LongWord read getDllHandle1;
protected
procedure DoDestroy(); override;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
TInitFrameFunc = function(const ApplicationHandle, parentHandle: LongWord):LongWord; stdcall;
procedure TForm1.DoDestroy();
begin
inherited;
if _dllHandle1 <> 0 then begin
FreeLibrary(_dllHandle1);
_dllHandle1 := 0;
end;
end;
function TForm1.getDllHandle1(): LongWord;
begin
if _dllHandle1 = 0 then _dllHandle1 := LoadLibrary('FrameInDLL\DllFrame1.dll');
Result := _dllHandle1;
end;
procedure TForm1.TabSheet1Show(Sender: TObject);
begin
//ShowMessage('Tab 1 Show');
end;
procedure TForm1.TabSheet2Show(Sender: TObject);
var initFrameFunc: TInitFrameFunc;
begin
if DllHandle1 <> 0 then begin
@initFrameFunc := GetProcAddress(DllHandle1, 'InitFrame');
if Assigned(initFrameFunc) then initFrameFunc(Application.Handle, TabSheet2.Handle)
else
ShowMessage('"InitFrame" function not found');
end
else begin
ShowMessage('DLL not found / not loaded');
end;
end;
procedure TForm1.TabSheet3Show(Sender: TObject);
begin
//ShowMessage('Tab 3 Show');
end;
end.
DLL项目文件:
library DllFrame1;
uses Windows, Controls, SysUtils, Classes, Forms, Unit1 in 'Unit1.pas' {Frame1: TFrame};
{$R *.res}
function InitFrame(const ApplicationHandle, parentHandle: LongWord): LongWord; stdcall; export;
var
Frame1: TFrame1;
AppHandle: THandle;
begin
AppHandle := Application.Handle;
Application.Handle := ApplicationHandle;
Frame1 := TFrame1.Create(Application);
Frame1.ParentWindow := ParentHandle;
SetParent(Frame1.Handle, ParentHandle);
Frame1.Align := alClient;
Frame1.Visible := True;
ShowWindow(Frame1.Handle, SW_SHOWMAXIMIZED);
Application.Handle := AppHandle;
Result := Frame1.Handle;
end;
exports InitFrame;
begin
end.
DLL中的一个框架:
unit Unit1;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TFrame1 = class(TFrame)
private
public
end;
implementation
{$R *.dfm}
end.