function EnumChildWndProc(AhWnd:LongInt;
AlParam:lParam):boolean;stdcall;
var
WndClassName: array[0..254] of Char;
WndCaption: array[0..254] of Char;
FCaption: String;
FTextLen: Integer;
begin
GetClassName(AhWnd,wndClassName,254);
GetWindowText(aHwnd,WndCaption,254);
with form1.memo1do
begin
lines.add( string(wndClassName));
lines.add( string(wndCaption));
lines.add('-------');
end;
result:=true;
if string(wndClassName)='Edit' then
begin
// l:=SendMessage(AhWnd,WM_GETTEXT,225,longint(s));
FTextLen := SendMessage(aHwnd, WM_GETTEXTLENGTH, 0, 0);
SetLength(FCaption,FTextLen + 1);
GetWindowText(aHwnd,PChar(FCaption),FTextLen + 1);
s:= Copy(FCaption,1,FTextLen);//这里原来是Caption我改成了S
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
hWnd:LongInt;
begin
memo1.Lines.Clear;
Memo1.Lines.Add(Edit1.Text+' 有如下控件类名称');
hWnd:=FindWindow(nil,pchar(Edit1.Text));
{FindWindowEx(0,0,'TForm1','登陆窗口');}
if hWnd<>0 then
EnumChildWindows(hWnd,@EnumChildWndProc,0)
else
MessageBox(self.handle,'没找到该窗口句柄','提示',0);
end;