Hook problem
-
Hi every body! I have created a global hook function (in Dll) to capture Keyboard events. Every a key has been pressed, the hook function send a user-defined message to my application. My problem is: My application can only receive the message, when it has focus. Could you tell me why? And How can I correct it? Thanks! //Hook function static LRESULT CALLBACK KeyboardHook(UINT nCode, WPARAM wParam, LPARAM lParam) { if( (nCode >=0) && (nCode == HC_ACTION) && (wParam == VK_SNAPSHOT)) PostMessage(hWndReceiver, UWM_CAPTURED,0,0); return CallNextHookEx(hookKeyBoard,nCode,wParam,lParam); } //Message Map BEGIN_MESSAGE_MAP(CTestHook, CDialog) ON_REGISTERED_MESSAGE(UWM_CAPTURED,OnCapture) //{{AFX_MSG_MAP(CTestDllDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP END_MESSAGE_MAP() // afx_msg bool OnCapture(WPARAM wParam, LPARAM lParam); xyz
-
Hi every body! I have created a global hook function (in Dll) to capture Keyboard events. Every a key has been pressed, the hook function send a user-defined message to my application. My problem is: My application can only receive the message, when it has focus. Could you tell me why? And How can I correct it? Thanks! //Hook function static LRESULT CALLBACK KeyboardHook(UINT nCode, WPARAM wParam, LPARAM lParam) { if( (nCode >=0) && (nCode == HC_ACTION) && (wParam == VK_SNAPSHOT)) PostMessage(hWndReceiver, UWM_CAPTURED,0,0); return CallNextHookEx(hookKeyBoard,nCode,wParam,lParam); } //Message Map BEGIN_MESSAGE_MAP(CTestHook, CDialog) ON_REGISTERED_MESSAGE(UWM_CAPTURED,OnCapture) //{{AFX_MSG_MAP(CTestDllDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP END_MESSAGE_MAP() // afx_msg bool OnCapture(WPARAM wParam, LPARAM lParam); xyz
Silly Boy wrote: My application can only receive the message, when it has focus. Does that imply that the
PostMessage()
statement is posting the message regardless of what window has the focus? If not, I'd be curious if any of the three conditions preceding thePostMessage()
statement are evaluating to FALSE.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)