delphi 递归获取窗口所有子窗口所以句柄


本文整理自网络,侵删。

 

unit Unit1;

interface

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

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

var
Form1: TForm1;

implementation

{$R *.dfm}
procedure GetChildWindows(h: HWND);
var
buf: array[0..255] of Char; {这个缓冲区是获取类名用的, 如果不需要可以删除}
begin
h := GetWindow(h, GW_CHILD); {第一个子窗口}
while h <> 0 do
begin
{下面两行是要执行的操作, 并假定只处理 TEdit}
GetClassName(h, buf, Length(buf));
//if buf = 'TEdit' then
ShowMessageFmt('%s:%d', [buf, h]);

h := GetWindow(h, GW_HWNDNEXT); {下一个子窗口}
GetChildWindows(h); {递归}
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
h:hwnd;
begin
h:=strtoint(edit1.Text);
GetChildWindows(h);


end;

end.

相关阅读 >>

Delphi 系统服务和普通forms程序共存一体的实现

Delphi xe6 android 界面皮肤美化 用stylebook

Delphi xe3中如何crc验证函数?

Delphi对cookie的操作

Delphi 调用dll运行正常,退出时弹出错误解决办法

Delphi nethttpclient post 函数

Delphi 判断特定字符是为单字节还是双字节

Delphi发送邮件―中文显示为乱码解决

Delphi 写dll注入器

Delphi edit只允许输入数字和小数点

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...