I'm trying to create a Windows hook, specifically to catch HSHELL_WINDOWCREATED messages.
However, my hook proc never gets called.
My dll has a function to install the hook:
hHook = SetWindowsHookEx(WH_SHELL, (HOOKPROC)CreateWindowHook, hinst, 0);
hinst was filled in by DllMain(), at the DLL_PROCESS_ATTACH message.
CreateWindowHook is defined as:
LRESULT CALLBACK CreateWindowHook(int code, WPARAM wParam, LPARAM lParam) {
if (code == HSHELL_WINDOWCREATED) {
// snip
}
return CallNextHookEx(0, code, wParam, lParam);
}
I expect the proc to be called whenever a new top level window is created, but it is never called. What am I missing? Thanks.
More information:
According to this article -- http://msdn.microsoft.com/en-us/library/ms644959(VS.85).aspx -- the app that wants to receive WH_SHELL messages has to register itself via SystemParametersInfo():
MINIMIZEDMETRICS st;
st.cbSize = sizeof(MINIMIZEDMETRICS);
st.iArrange = ARW_HIDE;
BOOL ret;
ret = SystemParametersInfo(
SPI_SETMINIMIZEDMETRICS,
sizeof(MINIMIZEDMETRICS),
&st,
0);
Is that call made in the dll, or the app that loads the dll containing the hook, or doesn't it matter?