1

参考我之前的问题,现在我有这个公式:

X := Round((X * ResolutionX) / Image1.Width); 
Y := Round((Y * ResolutionY) / Image1.Height); // where ResolutionX and ResolutionY is Client screen resolution.

将鼠标点击坐标发送到远程屏幕;准确且工作正常,除非我希望将点击发送到某个窗口的特定句柄,否则点击不会发生在确切的位置,例如:

var
  Title: array [0 .. 255] of Char;
begin
  GetWindowText(GetForegroundWindow, Title, 255);
  if Title <> '' then
  begin
    if ContainsStr(string(Title), '- Google Chrome') then
    begin
      WindowHandle := FindWindow(nil, PChar(string(Title))); // works fine to this handle.
      WindowHandle := FindWindowEx(WindowHandle, 0, 'Chrome_RenderWidgetHostHWND', nil); // not works with this, click have a distance of exaclty local.
    end;
  end;
end;

接收鼠标点击:

PostMessage(WindowHandle, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(PosX, PosY));
PostMessage(WindowHandle, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(PosX, PosY));

有什么解决办法吗?

4

1 回答 1

0

在 WM_LBUTTONDOWN 和 WM_LBUTTONUP 中,坐标是相对于窗口客户区的。您必须通过窗口的位置和窗口边框的偏移来偏移 X/Y 位置。

注意窗口可以是子窗口,所以必须计算父子关系链的偏移量。

Windows API 有一个功能:MapWindowPoints

于 2021-05-03T15:52:15.977 回答