我不确定问题是什么,我正在注册一个钩子并遵循文档。我已经阅读了所有内容,但由于某种原因它不起作用。它会告诉我钩子已安装,但它永远不会被调用。
我正在使用的代码如下:
#include <Windows.h>
#include <wchar.h>
HHOOK hHook;
LRESULT CALLBACK ShellProc(int nCode, WPARAM wParam, LPARAM lParam)
{
wprintf( TEXT("ShellProc called with iCode: %d\r\n"), nCode );
if( nCode == HSHELL_WINDOWCREATED )
{
HWND hWnd = (HWND)wParam;
wprintf( TEXT("New window created: %d\r\n"), hWnd );
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
int main()
{
hHook = SetWindowsHookEx(WH_SHELL, (HOOKPROC)ShellProc, NULL, GetCurrentThreadId());
if( hHook == NULL )
{
wprintf( TEXT("Failed to set windows hook\r\n") );
}
else
{
wprintf( TEXT("Windows hook set.\r\n") );
MINIMIZEDMETRICS st;
st.cbSize = sizeof(MINIMIZEDMETRICS);
st.iArrange = ARW_HIDE;
BOOL ret;
ret = SystemParametersInfo(
SPI_SETMINIMIZEDMETRICS,
sizeof(MINIMIZEDMETRICS),
&st,
0);
}
do
{
Sleep(100);
} while( !GetAsyncKeyState(VK_F5) );
if( hHook != NULL )
UnhookWindowsHookEx(hHook);
return 0;
}