For tracking user activity, I am using a Windows Hook for the main application thread, and monitor (among others) WM_COMMAND messages.
I receive them as expected from dialog buttons, toolbar buttons, accelerators and popup menus, but I do NOT receive them from the main menu.
Strangely enough, Spy++ does show the main window receiving them. What could be wrong?
Installing the hook:
currentHook = SetWindowsHookEx(WH_CALLWNDPROC,
HookProc, 0, GetCurrentThreadId());
HookProc, minimalistic:
LRESULT CALLBACK HookProc(int nCode, WPARAM wp, LPARAM lp)
{
CWPSTRUCT cwp = *(CWPSTRUCT *)lp;
if (cwp.message == WM_COMMAND)
{
ATLTRACE("[hook!] WM_COMMAND id=%d\n", LOWORD(cwp.wParam));
}
return CallNextHookEx(currentHook, nCode, wp, lp);
}
(The actual code is more complex, and needs to check for reentrancy etc., but I've remvoed it for this test)
Any ideas?
[Edit] the main window I test is an MFC application, but the instrumentation code does not use any MFC.