Discussion:
Q:How can I get window's handle by a mouseclick (just like spy++)
(too old to reply)
Theodore Cooper
2020-07-13 00:47:01 UTC
Permalink
Use C++!!
I want to get a editor's handle by a mouseclick, just like spy++ or PrtSc in Window 7.Thanks!
JJ
2020-07-13 07:02:21 UTC
Permalink
Use C++!! I want to get a editor's handle by a mouseclick, just like spy++
or PrtSc in Window 7.Thanks!
What you want to achieve involves 3 essential tasks (not just one; and
surely, not with just a single function): [1] monitor mouse clicks, [2] get
mouse cursor coordinate, and [3] get window handle at specific coordinate.

Considering that the window handle you want to get seems can be from other
application, the easiest method for monitoring mouse click would be by
periodically calling `GetAsyncKeyState()` with `VK_LBUTTON` argument. When
the mouse button is clicked, get the current mouse cursor using
`GetCursorPos()`, then pass the coordinate to `WindowFromPoint()`.
Loading...