简体   繁体   English

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

[英]How to check mouse click position is on required application?

I know the mouse click position using API GetCursorPos and the handle of application ( HWND ). 我知道使用API GetCursorPos和应用程序HWNDHWND )的鼠标单击位置。

How can I check mouse click position is on this application? 如何检查此应用程序上的鼠标单击位置?

My view: 我的观点:

  • Get the bounding box of application from its handle. 从其句柄获取应用程序的边界框。 ( GetWindowRect(hWnd, &rect); ) GetWindowRect(hWnd, &rect);
  • Check cursor position lies in this bounding box. 检查光标位置在此边界框中。 ( PtInRect(&rect, p) ) PtInRect(&rect, p)

This is not working if windows are overlapping. 如果窗口重叠,则无法使用。

As we know the handle of targeted screen handle and click cursor position: 我们知道目标屏幕的句柄和单击光标位置:

// 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 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM