如果我知道某个控件的Handle值,怎么通过程序得到该控件的实例? RT 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 再补充下:就是我想在DLL文件中处理我取到的控件。不是在应用程序中取。因为有FindControl函数可以使用。在这里我想通过DLL来处理。如果知道的就请告诉,谢谢! //下面为DLLlibrary findCtrl;uses SysUtils, Classes, Unit1 in 'Unit1.pas';{$R *.res} exports GetString, FindCtrol;beginend.//DLL的单元unit Unit1;interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; function FindCtrol(handle: THandle): TWinControl; stdcall;implementationfunction FindCtrol(handle: THandle): TWinControl; stdcall;begin Result := FindControl(handle);end;end.//下面为调用DLLunit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TFindCtrol = function (handle: THandle): TWinControl; stdcall; TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var myFindCtrol: TFindCtrol; Ctrol: TWinControl; Hwd: Cardinal;begin Hwd := LoadLibrary(Pchar('F:\Dll\findCtrl.dll')); try if Hwd <> 0 then begin myFindCtrol := GetProcAddress(Hwd, Pchar('FindCtrol')); if @myFindCtrol <> nil then Ctrol := myFindCtrol(Button1.Handle); end; if Ctrol <> nil then ShowMessage(Ctrol.Name); finally if Hwd <> 0 then FreeLibrary(Hwd); end;end;end.//记住每个工程里面都得调用 vcl这个运行包. 把每个工程的 build with runtime packages 勾上就可以了. 如何获得不连续的随机数 请大家帮忙一个'花生壳'的问题 关于调用windows内核问题×××××××××××× 怎么使用datatype属性 有那位大侠知道 在写WINDOWS2000日志文件的时候 所需要的资源文件格式 dbgrid,如何增加一行啊? sql 中的错误,大家帮忙 请问高手怎样把开始菜单中的 开始 换成别的字符 TADodataset的更新当前记录的方法 远程桌面不能拷贝文件的问题 程序报错说无法装载midas.dll,怎么办? 谁在delphi中使用过DSO或能提供资料者有分!!!!
如果知道的就请告诉,谢谢!
library findCtrl;
uses
SysUtils,
Classes,
Unit1 in 'Unit1.pas';{$R *.res}
exports
GetString,
FindCtrol;
begin
end.
//DLL的单元
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls; function FindCtrol(handle: THandle): TWinControl; stdcall;
implementationfunction FindCtrol(handle: THandle): TWinControl; stdcall;
begin
Result := FindControl(handle);
end;
end.//下面为调用DLL
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TFindCtrol = function (handle: THandle): TWinControl; stdcall;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
myFindCtrol: TFindCtrol;
Ctrol: TWinControl;
Hwd: Cardinal;
begin
Hwd := LoadLibrary(Pchar('F:\Dll\findCtrl.dll'));
try
if Hwd <> 0 then
begin
myFindCtrol := GetProcAddress(Hwd, Pchar('FindCtrol'));
if @myFindCtrol <> nil then
Ctrol := myFindCtrol(Button1.Handle);
end;
if Ctrol <> nil then
ShowMessage(Ctrol.Name);
finally
if Hwd <> 0 then
FreeLibrary(Hwd);
end;
end;end.
//记住每个工程里面都得调用 vcl这个运行包. 把每个工程的 build with runtime packages 勾上就可以了.