I want to Hook Mouse but failed?
-
I use following code to hook other program's MOUSE message:
m_hHook=SetWindowsHookEx(WH_MOUSE,HookProc,AfxGetInstanceHandle(),dwReturn);
the varm_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! -
I use following code to hook other program's MOUSE message:
m_hHook=SetWindowsHookEx(WH_MOUSE,HookProc,AfxGetInstanceHandle(),dwReturn);
the varm_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! -
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!
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!
-
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!