function GetButtonHandle(hwnd: Integer; lparam: Longint):Boolean; stdcall;
var
Buffer : array [0..255] of Char;
Buffer1: array [0..255] of Char;
begin
Result := True;
GetClassName(hwnd,buffer,256);
if StrPas(Buffer) = 'Button' then
begin
GetWindowText(hwnd,Buffer1,100);
if StrPas(Buffer1) = '下一步(&N) >' then
begin
PInteger(lparam)^ := hwnd; //得到目标控件的Hwnd(句柄)
Result := false;
end;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
Handle, Handle1: Integer;
begin
Handle := FindWindow(nil,'网络设置');
if Handle <> 0 then
begin
txt := '下一步(&N) >';
// 找完成按键
EnumChildWindows(Handle,@GetButtonHandle,Integer(@Handle));
finishb := Handle;
// 找到了 '完成' 按钮 handle
SendMessage(finishb,WM_LBUTTONDOWN,0,0);
SendMessage(finishb,WM_LBUTTONUP,0,0);
end;
Handle1 := FindWindow(nil,'完成');
if Handle1 <> 0 then
begin
txt := '< 上一步(&B)';
// 找完成按键
EnumChildWindows(Handle1,@GetButtonHandle,Integer(@Handle1));
finishb := Handle1;
// 找到了 '完成' 按钮 handle
SendMessage(finishb,WM_LBUTTONDOWN,0,0);
SendMessage(finishb,WM_LBUTTONUP,0,0);
end;
end;