Mouse Hook Problem
-
Hi All, I am getting this weird problem for the past 4 days. Anyone seen this before? I am trying to monitor mouse events on a specific application (Windows XP calculator calc.exe). I have set a hook on the Hwnd pointer of calc using hook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)msghook, hInst, GetWindowThreadProcessId(hWnd, NULL)); and then I use the following to detect messages static LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam) { char text[10]; if(nCode < 0) { /* pass it on */ CallNextHookEx(hook, nCode, wParam, lParam); return 0; } /* pass it on */ LPMSG msg = (LPMSG)lParam; switch(msg->message) { case WM_LBUTTONDOWN: case WM_NCLBUTTONDOWN: PostMessage(hWndServer, UWM_LBUTTONDOWN, WM_LBUTTONDOWN, msg->lParam); break; case WM_LBUTTONUP: case WM_NCLBUTTONUP: PostMessage(hWndServer, UWM_LBUTTONUP, WM_LBUTTONUP, msg->lParam); break; case WM_MOUSEMOVE: case WM_NCMOUSEMOVE: PostMessage(hWndServer, UWM_MOUSEMOVE, WM_MOUSEMOVE, msg->lParam); break; } return CallNextHookEx(hook, nCode, wParam, lParam); } What happens is that WM_LBUTTONDOWN comes in fine but the WM_LBUTTONUP never comes in, instead a mousemove message shows up (EVEN WHEN THE MOUSE IS NOT MOVING). Its very erratic. Sometimes the WM_LBUTTONUP case does execute but very rarely. Am I doing something wrong? If I use WH_MOUSE or WH_CBT instead of WH_GETMESSAGE, none of the cases gets called. Has anyone had this kind of problem before. By the way my mouse is not faulty. I tried this code on a number of PCs with the same result. Thanks in advance. Regards, Zahid
-
Hi All, I am getting this weird problem for the past 4 days. Anyone seen this before? I am trying to monitor mouse events on a specific application (Windows XP calculator calc.exe). I have set a hook on the Hwnd pointer of calc using hook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)msghook, hInst, GetWindowThreadProcessId(hWnd, NULL)); and then I use the following to detect messages static LRESULT CALLBACK msghook(UINT nCode, WPARAM wParam, LPARAM lParam) { char text[10]; if(nCode < 0) { /* pass it on */ CallNextHookEx(hook, nCode, wParam, lParam); return 0; } /* pass it on */ LPMSG msg = (LPMSG)lParam; switch(msg->message) { case WM_LBUTTONDOWN: case WM_NCLBUTTONDOWN: PostMessage(hWndServer, UWM_LBUTTONDOWN, WM_LBUTTONDOWN, msg->lParam); break; case WM_LBUTTONUP: case WM_NCLBUTTONUP: PostMessage(hWndServer, UWM_LBUTTONUP, WM_LBUTTONUP, msg->lParam); break; case WM_MOUSEMOVE: case WM_NCMOUSEMOVE: PostMessage(hWndServer, UWM_MOUSEMOVE, WM_MOUSEMOVE, msg->lParam); break; } return CallNextHookEx(hook, nCode, wParam, lParam); } What happens is that WM_LBUTTONDOWN comes in fine but the WM_LBUTTONUP never comes in, instead a mousemove message shows up (EVEN WHEN THE MOUSE IS NOT MOVING). Its very erratic. Sometimes the WM_LBUTTONUP case does execute but very rarely. Am I doing something wrong? If I use WH_MOUSE or WH_CBT instead of WH_GETMESSAGE, none of the cases gets called. Has anyone had this kind of problem before. By the way my mouse is not faulty. I tried this code on a number of PCs with the same result. Thanks in advance. Regards, Zahid
Have you tried WH_CALLWNDPROC or WH_CALLWNDPROCRET? -- Joel Lucsy