Hey, I'm using Windows Hook, I installed the mouse hook, system-wide and its working perfectly. Now there is a problem, I need to the get window handle on which the mouse was clicked.. How do I do that? Does the Mouse hook event passes us that information?
A:
Use the WindowFromPoint
function to get the window under a given location.
SLaks
2009-10-29 14:01:26
But what if the user changed the window quickly? I may get the wrong handle right?
hab
2009-10-29 14:06:22
If you call it inside the mouse hook, I don't think so.
SLaks
2009-10-29 14:11:02
The mouse hook event also gives us the MOUSEHOOKSTRUCT, but its hwnd value is null, but its NULL, do you know why?
hab
2009-10-29 14:12:06
I don't know; Google it.
SLaks
2009-10-29 14:13:42
did you install a low level mouse hook, or a simple mouse hook ?
Adrien Plisson
2009-10-29 14:31:48
I did SetWindowsHookEx, which one is that?
hab
2009-10-29 14:52:18
@manzoor: it's the same call for the two types of hook, only the value of the idHook parameter change. what i want to know is whether you used WH_MOUSE_LL or WH_MOUSE ?
Adrien Plisson
2009-10-29 16:13:27
I used WH_MOUSE_LL
hab
2009-10-29 18:10:06
See my second answer.
SLaks
2009-10-29 19:57:58
@SLaks: thank you.
Adrien Plisson
2009-10-29 20:10:58
A:
Assuming you set a WH_MOUSE hook, your MouseProc receives a pointer to a MOUSEHOOKSTRUCT struct. Since the hwnd member is NULL, you could try using WindowFromPoint with the pt member of the struct. The pt member is the coordinate at the time the message was created.
sean e
2009-10-29 16:16:07
+1
A:
Since you're using WH_MOUSE_LL
, you're making a low-level mouse hook, which actually receives a pointer to a MSLLHOOKSTRUCT
that doesn't have an hwnd
member.
You need to set a normal mouse hook using WH_MOUSE
; you'll then get a pointer to the MOUSEHOOKSTRUCT
that you're expecting..
SLaks
2009-10-29 19:56:40