小CASE,50大洋成交(如何获得DLL中 FORM 的 Height 和 Width 等属性(50分)

  • 主题发起人 主题发起人 喜洋洋
  • 开始时间 开始时间

喜洋洋

Unregistered / Unconfirmed
GUEST, unregistred user!
我需要返回一个DLL 中 FORM 的 ClientHeigth 和ClientWidth 的值,我该
如何写DLL中的接口,如何调用;
 
(1)带窗体的动态链接库:
library Project1;

uses
SysUtils,
Classes,
Forms,
Unit1 in 'Unit1.pas' {FormDll};

{$R *.RES}

function GetDllForm: TForm;
begin
Result := FormDll;
end;

exports
GetDllForm;

begin
end.

<hr>
(2)动态链接库的窗体:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TFormDll = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

var
FormDll: TFormDll;

implementation

{$R *.DFM}

initialization
begin
FormDll := TFormDll.Create(Application);
end;

finalization
begin
FormDll.Free;
end;

end.

<hr>
(3)如何调用:
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

function GetDllForm: TForm;

implementation

{$R *.DFM}

function GetDllForm: TForm; external 'project1.dll';

procedure TForm1.Button1Click(Sender: TObject);
var
AForm: TForm;
begin
AForm := GetDLLForm;
ShowMessage(Format('ClientHeight=%d ClientWidth=%d', [AForm.ClientHeight, AForm.ClientWidth]));
end;

end.
 
呵呵,真是快手!
 
如果这个FORM是MDI子窗口的话,建议使用SendMessage发回来就可以了,
重载一下父窗口的WindProc函数就可以了。
如DLL窗体中写成:
SendMessage(ParentForm.Handle, Wm_USER+1, Self.Width, Welf.Height)
父窗口的WndProc中写成:
case Msg.Msg of
WM_USER+1 :
begin
//msg.wParam 和msg.lParam就是传回来的值。
end;
 
多人接受答案了。
 

Similar threads

后退
顶部