[此贴子已经被作者于2007-8-4 13:42:34编辑过]
[此贴子已经被作者于2007-8-4 13:42:34编辑过]
给你段小例子
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Edit1: TEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
function EnumChildControlsWndProc(AhWnd:LongInt;
AlParam:lParam):boolean;stdcall;
implementation
{$R *.dfm}
function EnumChildControlsWndProc(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('begin***********************');
lines.add( 'ClassName: ' + string(wndClassName));
lines.add( 'Text/Caption: ' + string(wndCaption));
lines.add('***********************end' + #13#10);
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,@EnumChildControlsWndProc,0);
end
else
begin
ShowMessage('指定窗口不存在,请重新输入.');
end;
end;
end.
[此贴子已经被作者于2007-8-6 10:36:24编辑过]