unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function EnumChildWndProc(AhWnd: LongInt; AlParam: lParam): boolean; stdcall;
var
WndClassName: array[0…254] of Char;
WndCaption: array[0…254] of Char;
begin
GetClassName(AhWnd, WndClassName, 254);
GetWindowText(AhWnd, WndCaption, 254);
with form1.memo1 do
begin
lines.add( WndClassName);
lines.add(WndCaption);
lines.add('-------');
end;
result := true;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
hWnd: LongInt;
begin
memo1.Lines.Clear;
Memo1.Lines.Add(Edit1.Text + ’ 有如下控件类名称’);
hWnd := FindWindow(nil, pchar(Edit1.Text));
if hWnd <> 0 then
begin
EnumChildWindows(hWnd, @EnumChildWndProc, 0);
end
else
MessageBox(self.handle, ‘没找到该窗口句柄’, ‘提示’, 0);
end;
end.