delphi获取指定窗体句柄,该怎么处理
1个回答
推荐于2018-04-21
展开全部
找某个窗口的某个BUTTON ,例子很简单就是用了
FindWindow,EnumChildWindows两个函数,要找的具体BUTTON在EnumChildWindowsProc回调函数中
Delphi(Pascal) codefunction EnumChildWindowsProc(hwd: Hwnd): Boolean; stdcall;
begin
Result := true;
GetClassName(hwd, buffer, 256);
if String(Buffer) <> 'Button' then Exit;
getwindowtext(hwd, buffer, 256);
if String(Buffer) <> '验证全部' then Exit;
h := hwd;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
hwnd1,hwnd2,hwnd3,hwnd4: DWORD;
begin
h := 0;
hwnd1 := FindWindow(nil, '代理猎手');
if hwnd1 <> 0 then
begin
if EnumChildWindows(hwnd1, @EnumChildWindowsProc, 0) then
if h = 0 then exit;
SendMessage(h, WM_LBUTTONDOWN , 0, 0);
SendMessage(h,WM_LBUTTONUp, 0, 0);
end;
end;
FindWindow,EnumChildWindows两个函数,要找的具体BUTTON在EnumChildWindowsProc回调函数中
Delphi(Pascal) codefunction EnumChildWindowsProc(hwd: Hwnd): Boolean; stdcall;
begin
Result := true;
GetClassName(hwd, buffer, 256);
if String(Buffer) <> 'Button' then Exit;
getwindowtext(hwd, buffer, 256);
if String(Buffer) <> '验证全部' then Exit;
h := hwd;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
hwnd1,hwnd2,hwnd3,hwnd4: DWORD;
begin
h := 0;
hwnd1 := FindWindow(nil, '代理猎手');
if hwnd1 <> 0 then
begin
if EnumChildWindows(hwnd1, @EnumChildWindowsProc, 0) then
if h = 0 then exit;
SendMessage(h, WM_LBUTTONDOWN , 0, 0);
SendMessage(h,WM_LBUTTONUp, 0, 0);
end;
end;
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询