System-wide hook does not work with Explorer?
Posted on 2003-11-15
In my program, I have one WH_MOUSE hook which monitors the mouse throughout the system.
As an example, I put the following code into hook procedure
if (wParam == WM_NCLBUTTONDOWN)
if (pMst->wHitTestCode == HTCAPTION)
GetModuleFileName(NULL, szTemp, 256);
I check if wParam is WM_NCLBUTTONDOWN, and if so whether the mouse cursor is on title bar or not.
If it is, then i get the module file name and change the window title to be its module file name.
Everything works fine for most programs like notepad, messenger, internet explorer.
Notepad will be replaced by C:\Windows\notepad.exe
So i think there is nothing wrong with the code.
However, explorer does not work (like My Computer)
It looks like the hook procedure does not catch the message for explorer.
So i tried the following code
HWND hProgman = FindWindow(TEXT("Progman"), TEXT("Program Manager"));
dwThreadID = GetWindowThreadProcessId(hProgman, NULL);
if (dwThreadID != NULL)
hProgmanHook = SetWindowsHookEx(WH_MOUSE,(HOOKPROC)ProgmanProc, g_hInstanceDll, dwThreadID);
Instead of putting a system-wide hook, but put the hook right into Progman (Which i think is explorer.exe)
However, the code still does not work.
Is there anyway to get message from explorer?