D
Am besten ist es, wenn du WH_MOUSE_LL hookst, da dieser Hook immer global ist.
Hier mal ein kleines Beispiel:
#include <stdio.h>
#include <windows.h>
HHOOK maus;
int i=0;
__declspec (dllexport) LRESULT CALLBACK mausaktion(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
return -1;
if (nCode == HC_ACTION)
{
printf("%d: maus aktion\n", i);
i++;
}
return(CallNextHookEx(maus, nCode, wParam, lParam));
}
void hook(void)
{
maus=SetWindowsHookEx(WH_MOUSE_LL,(HOOKPROC)mausaktion,GetModuleHandle(0),0);
}
void unhook(void)
{
UnhookWindowsHookEx(maus);
}
int main(int argc,char *argv[])
{
MSG msg;
hook();
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
unhook();
return(0);
}
Alles weitere steht in der MSDN Library:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/mouseproc.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookstructures/msllhookstruct.asp