cermi
August 26th, 2008, 08:56 AM
Hello,
I'm trying to hook a window procedure in different window. I've added my custom item to window menu of the hooked window. As far everything's good.
The problem is that my hook procedure doesn't detect the WM_SYSCOMMAND message generated by clicking on the window menu item. I detect only WM_SYSCOMMAND messages related to opening the window menu or after manipulation with window (like moving or resizing the window). But the message is issued because I can "catch" it in the window's own window procedure (because I'm hooking my own test application). What can be wrong?
The hook procedure:
WINHOOKS_API LRESULT CALLBACK PinHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode >= 0)
{
CWPSTRUCT *msg = (CWPSTRUCT*)lParam;
if (msg->message==WM_SYSCOMMAND)
{
OutputDebugStringA("sys cmd");
}
if (msg->message==WM_MENUCOMMAND ) OutputDebugStringA("menu cmd");
/*if (msg->message!= WM_MOUSEMOVE && msg->message!=32 && msg->message!=132) {
char b[500];
sprintf(b,"WM: %d",msg->message);
//OutputDebugStringA(b);
}*/
} else OutputDebugStringA("must ignore message");
LRESULT nextRet=CallNextHookEx(NULL,nCode,wParam,lParam);
return nextRet;
}
Hook install procedure:
HHOOK InstallHook(HWND hWnd)
{
DWORD thrID = GetWindowThreadProcessId(hWnd,NULL);
if (thrID==0) { tcout << "error in getting thread id " << endl; return NULL;}
HHOOK hHook = SetWindowsHookEx(WH_CALLWNDPROC,(HOOKPROC)HookProc,hHookLib,0);
if (hHook==NULL) { tcout << "error in hook install " <<GetLastError() << endl; return NULL;}
return hHook;
}
All function returns no error. As I said, the hook proc can catch most of the messages (e.g. all messages I send to it with SendMessage/PostMessage, ...), but not the one I need.
What I'm doing wrong?
I'm trying to hook a window procedure in different window. I've added my custom item to window menu of the hooked window. As far everything's good.
The problem is that my hook procedure doesn't detect the WM_SYSCOMMAND message generated by clicking on the window menu item. I detect only WM_SYSCOMMAND messages related to opening the window menu or after manipulation with window (like moving or resizing the window). But the message is issued because I can "catch" it in the window's own window procedure (because I'm hooking my own test application). What can be wrong?
The hook procedure:
WINHOOKS_API LRESULT CALLBACK PinHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode >= 0)
{
CWPSTRUCT *msg = (CWPSTRUCT*)lParam;
if (msg->message==WM_SYSCOMMAND)
{
OutputDebugStringA("sys cmd");
}
if (msg->message==WM_MENUCOMMAND ) OutputDebugStringA("menu cmd");
/*if (msg->message!= WM_MOUSEMOVE && msg->message!=32 && msg->message!=132) {
char b[500];
sprintf(b,"WM: %d",msg->message);
//OutputDebugStringA(b);
}*/
} else OutputDebugStringA("must ignore message");
LRESULT nextRet=CallNextHookEx(NULL,nCode,wParam,lParam);
return nextRet;
}
Hook install procedure:
HHOOK InstallHook(HWND hWnd)
{
DWORD thrID = GetWindowThreadProcessId(hWnd,NULL);
if (thrID==0) { tcout << "error in getting thread id " << endl; return NULL;}
HHOOK hHook = SetWindowsHookEx(WH_CALLWNDPROC,(HOOKPROC)HookProc,hHookLib,0);
if (hHook==NULL) { tcout << "error in hook install " <<GetLastError() << endl; return NULL;}
return hHook;
}
All function returns no error. As I said, the hook proc can catch most of the messages (e.g. all messages I send to it with SendMessage/PostMessage, ...), but not the one I need.
What I'm doing wrong?