如何检查鼠标点击位置是否在所需的应用程序上?

问题描述 投票:0回答:1

我知道使用API​​ GetCursorPos和应用程序句柄(HWND)的鼠标单击位置。

如何检查此应用程序上的鼠标点击位置?

我的看法:

  • 从其句柄中获取应用程序的边界框。 (GetWindowRect(hWnd, &rect);
  • 检查光标位置是否在此边界框中。 (PtInRect(&rect, p)

如果窗口重叠,这不起作用。

c++ winapi window
1个回答
0
投票

我们知道目标屏幕句柄的手柄和点击光标位置:

// hWnd : Already known windows handle

GetCursorPos(&p);
HWND hWndFromPoint = WindowFromPoint(p);

// If the handle got from click point is child of the desire window means it is clicked on the desire window itself.
if (IsChild(hWnd, hWndFromPoint))
{
    // Do something on Mouse click 
}
© www.soinside.com 2019 - 2024. All rights reserved.