假设您要单击窗口上的控件,该控件相对于窗口的位置已知,您可以从中获得(可以获得)句柄,您可以使用它。仅在当前表单上演示。也许适应你的条件。
Procedure SetWindowTopAndClickOnRelPos(wnd:HWND;Pos:TPoint);
var
ChildControlHandle:HWND;
begin
SetForegroundWindow(wnd);
ChildControlHandle:= ChildWindowFromPoint(WND,pos);
SendMessage(ChildControlHandle,WM_LButtonDown,0,5*$FFFF + 5);
SendMessage(ChildControlHandle,WM_LButtonUp,0,5*$FFFF + 5);
Form4.Memo1.Lines.Add(Format('ChildControlHandle: %d',[ChildControlHandle]));
end;
procedure TForm4.Button1Click(Sender: TObject);
begin
Memo1.Lines.Add(Format('Window: %d',[Handle]));
Memo1.Lines.Add(Format('Button: %d',[button2.Handle]));
SetWindowTopAndClickOnRelPos(handle,Point(Button2.Left + 2,Button2.Top + 2));
end;
procedure TForm4.Button2Click(Sender: TObject);
begin
Showmessage('Hallo');
end;