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

How to check mouse click position is on required application?

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

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

我的看法:

如果 windows 重叠,这将不起作用。

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

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