看来猩猩提问还是比较少的,我就有个超级简单的问题, 请教各位大佬
DWGZ 2005-01-18 01:12:50 大家如果认识我,不准笑我哦,真晕,居然这么简单的问题整了我半天,真是受不了
//TestDLL
library TestDLL;
uses
ShareMem,
SysUtils,
Controls,
StdCtrls,
Forms,
Windows,
Dialogs,
Classes;
{$R *.res}
var
OldScreen: TScreen;
OldApp: TApplication;
procedure TestWinControl1; stdcall;
var
Edit1: TEdit;
begin
Edit1 := TEdit.Create(nil);
try
if Edit1.InheritsFrom(TWinControl) then
ShowMessage('I is wincontrol')
else
ShowMessage('I is not wincontrol')
finally
Edit1.Free;
end;
end;
procedure TestWinControl2; stdcall;
var
I: Integer;
ActiveFrm: TForm;
begin
ActiveFrm := Screen.ActiveForm;
if ActiveFrm = nil then Exit;
for I := 0 to ActiveFrm.ComponentCount - 1 do
begin
if ActiveFrm.Components[I].InheritsFrom(TWinControl) then
ShowMessage(ActiveFrm.Components[I].Name + ' is wincontrol')
else
ShowMessage(ActiveFrm.Components[I].Name + ' is not wincontrol');
end;
end;
procedure DllEntry(Reason: DWORD);
begin
case Reason of
DLL_PROCESS_ATTACH:
begin
OldScreen := Screen;
OldApp := Application;
end;
DLL_PROCESS_DETACH:
begin
Screen := OldScreen;
Application := OldApp;
end;
end;
end;
procedure InitDLL(pScreen: TScreen; pApplication: TApplication); stdcall;
begin
Screen := pScreen;
Application := pApplication;
end;
exports
InitDLL,
TestWinControl1,
TestWinControl2;
begin
DllProc := @DllEntry;
DllEntry(DLL_PROCESS_ATTACH);
end.
//TestProject=====================================================
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure TestWinControl1; stdcall; external 'TestDLL.dll';
procedure TestWinControl2; stdcall; external 'TestDLL.dll';
procedure InitDLL(pScreen: TScreen; pApplication: TApplication); stdcall; external 'TestDLL.dll';
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
TestWinControl1;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
TestWinControl2;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
InitDLL(Screen, Application);
end;
end.