Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Mouse Hook Problem

Mouse Hook Problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zee man
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • Z Zee man

      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

      J Offline
      J Offline
      Joel Lucsy
      wrote on last edited by
      #2

      Have you tried WH_CALLWNDPROC or WH_CALLWNDPROCRET? -- Joel Lucsy

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups