How to use global hook with WH_GETMESSAGE
-
Dear all: I try to use global hook with WH_GETMESSAGE, but still failed. It work only on my application, not global. My code show as below:
#pragma data_seg (".SHARED")
HHOOK g_hPreviousMsgHook = 0;
HINSTANCE g_hInstance = 0;
#pragma data_seg()
#pragma comment(linker, "/SECTION:.SHARED,RWS")BOOL CSoundDllApp::InitInstance()
{
CWinApp::InitInstance();
g_hInstance = AfxGetInstanceHandle();
return TRUE;
}BOOL InstallWinHook()
{
BOOL bReturn = TRUE;
g_hPreviousMsgHook = SetWindowsHookEx(WH_GETMESSAGE,
&MsgHookProcedure, g_hInstance, 0);if(NULL == g\_hPreviousMsgHook) { bReturn = FALSE; } return bReturn;
}
LRESULT CALLBACK MsgHookProcedure(int nCode, WPARAM wParam, LPARAM lParam)
{
if(0 > nCode)
return CallNextHookEx(g_hPreviousMsgHook, nCode,
wParam, lParam);
PMSG data = (PMSG)lParam;switch(data->message) { case WM\_POINTERDOWN: Beep(0x7fff, 1000); break; } return CallNextHookEx(g\_hPreviousMouseHook, nCode, wParam, lParam);
}
I set 0 into last parameter of setWindowsHookEx api, but it seem like not work. Could someone tell me where's wrong, please? Thanks for your help, Victor
-
Dear all: I try to use global hook with WH_GETMESSAGE, but still failed. It work only on my application, not global. My code show as below:
#pragma data_seg (".SHARED")
HHOOK g_hPreviousMsgHook = 0;
HINSTANCE g_hInstance = 0;
#pragma data_seg()
#pragma comment(linker, "/SECTION:.SHARED,RWS")BOOL CSoundDllApp::InitInstance()
{
CWinApp::InitInstance();
g_hInstance = AfxGetInstanceHandle();
return TRUE;
}BOOL InstallWinHook()
{
BOOL bReturn = TRUE;
g_hPreviousMsgHook = SetWindowsHookEx(WH_GETMESSAGE,
&MsgHookProcedure, g_hInstance, 0);if(NULL == g\_hPreviousMsgHook) { bReturn = FALSE; } return bReturn;
}
LRESULT CALLBACK MsgHookProcedure(int nCode, WPARAM wParam, LPARAM lParam)
{
if(0 > nCode)
return CallNextHookEx(g_hPreviousMsgHook, nCode,
wParam, lParam);
PMSG data = (PMSG)lParam;switch(data->message) { case WM\_POINTERDOWN: Beep(0x7fff, 1000); break; } return CallNextHookEx(g\_hPreviousMouseHook, nCode, wParam, lParam);
}
I set 0 into last parameter of setWindowsHookEx api, but it seem like not work. Could someone tell me where's wrong, please? Thanks for your help, Victor
-
This message is directly tied to your message queue as described at http://msdn.microsoft.com/en-us/library/windows/desktop/ms644959(v=vs.85).aspx#whgetmessagehook[^].
Dear Richard: It mean I just hook message only from application message queue, so I can not get message from anthor place? When I touch on some applications, it works. When I touch on desktop, it does not work. How? Does it mean the touch message on desktop not exist in application message queue? Thanks for your help, Victor
-
Dear Richard: It mean I just hook message only from application message queue, so I can not get message from anthor place? When I touch on some applications, it works. When I touch on desktop, it does not work. How? Does it mean the touch message on desktop not exist in application message queue? Thanks for your help, Victor