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. I want to Hook Mouse but failed?

I want to Hook Mouse but failed?

Scheduled Pinned Locked Moved C / C++ / MFC
debugginghelpquestion
4 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.
  • W Offline
    W Offline
    white jungle
    wrote on last edited by
    #1

    I use following code to hook other program's MOUSE message: m_hHook=SetWindowsHookEx(WH_MOUSE,HookProc,AfxGetInstanceHandle(),dwReturn); the var m_hHook is defined for record the MOUSE HOOK,and these code whin a dll program.dwReturn was a var for a Dlg based program's thread ID. when I debug it,I found that it it can set hook to the Dlg based program.but the process HookProc was never be called. is there some error in my code?But my code just simple as above. And the HookProc as follow: LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam ) { //I set a breakpoint here ,but never run to here! return CallNextHookEx(m_hHook,nCode,wParam,lParam); } In my opinion,everything is OK! But when I click my mouse in the DLG based program,the process HookProc had never been execute! IS there somethingwrong? Don't look at me in that way!

    S 1 Reply Last reply
    0
    • W white jungle

      I use following code to hook other program's MOUSE message: m_hHook=SetWindowsHookEx(WH_MOUSE,HookProc,AfxGetInstanceHandle(),dwReturn); the var m_hHook is defined for record the MOUSE HOOK,and these code whin a dll program.dwReturn was a var for a Dlg based program's thread ID. when I debug it,I found that it it can set hook to the Dlg based program.but the process HookProc was never be called. is there some error in my code?But my code just simple as above. And the HookProc as follow: LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam ) { //I set a breakpoint here ,but never run to here! return CallNextHookEx(m_hHook,nCode,wParam,lParam); } In my opinion,everything is OK! But when I click my mouse in the DLG based program,the process HookProc had never been execute! IS there somethingwrong? Don't look at me in that way!

      S Offline
      S Offline
      Simon W 0
      wrote on last edited by
      #2

      If you use global hook you should assure that the hookproc is in a dll module, make sure that the instance is your dll module instance,and the last parameter must be 0 I am seeking... For what? Why did you ask me for what? I don't know!

      W 1 Reply Last reply
      0
      • S Simon W 0

        If you use global hook you should assure that the hookproc is in a dll module, make sure that the instance is your dll module instance,and the last parameter must be 0 I am seeking... For what? Why did you ask me for what? I don't know!

        W Offline
        W Offline
        white jungle
        wrote on last edited by
        #3

        I am sure that the process HookProc is in a dll module.And the instance is the dll module instance.And I only want hook a dlg based program not global.So I think the 4th paramter is the Thread ID of the Dlg based program. All of these parameters are checked correct. By the way,If I make the 4th parameter to 0,the HookProc will be called when the mouse message was occured.And everything is OK! But I only want to Hook a special Program. How can I do? thank you for help me! :laugh: Don't look at me in that way!

        S 1 Reply Last reply
        0
        • W white jungle

          I am sure that the process HookProc is in a dll module.And the instance is the dll module instance.And I only want hook a dlg based program not global.So I think the 4th paramter is the Thread ID of the Dlg based program. All of these parameters are checked correct. By the way,If I make the 4th parameter to 0,the HookProc will be called when the mouse message was occured.And everything is OK! But I only want to Hook a special Program. How can I do? thank you for help me! :laugh: Don't look at me in that way!

          S Offline
          S Offline
          Simon W 0
          wrote on last edited by
          #4

          if you want install a local hook,the instance parameter should be NULL and the last parameter is the ID of your thread I am seeking... For what? Why did you ask me for what? I don't know!

          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