#include <iostream>
#include <windows.h>
using namespace std;
HHOOK Hook;
HMODULE Mod;
LRESULT CALLBACK CallWndProc(int code, WPARAM wParam, LPARAM lParam)
{
if(code == HC_ACTION)
{
PCWPSTRUCT info = (PCWPSTRUCT)lParam;
return CallNextHookEx(Hook,code,wParam,lParam);
}
}
int main()
{
MSG msg;
Mod = GetModuleHandle(NULL);
if(!Mod)
{
return 0;
}
Hook = SetWindowsHookEx(WH_CALLWNDPROC,CallWndProc,Mod,0);
if(!Hook)
{
return 0;
}
GetMessage(&msg,0,0,0);
cin.get();
}
HHOOK SetWindowsHookEx(
int idHook,
HOOKPROC lpfn,
HINSTANCE hMod,
DWORD dwThreadId
);
idHook
[in] Specifies the type of hook procedure to be installed. This parameter can be one of the following values.
WH_CALLWNDPROC
Installs a hook procedure that monitors messages before the system sends them to the destination window procedure. For more information, see the CallWndProc hook procedure.
#include <iostream>
#include <windows.h>
using namespace std;
HHOOK Hook;
HMODULE Mod;
MSG *msg;
LRESULT CALLBACK Proc(int code, WPARAM wParam, LPARAM lParam)
{
msg = (MSG*)lParam;
if(msg)
{
cout <<"Test";
}
return CallNextHookEx(Hook,code,wParam,lParam);
}
int main()
{
Mod = GetModuleHandle(NULL);
if(!Mod)
{
return 0;
}
Hook = SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)Proc,Mod,0);
if(!Hook)
{
return 0;
}
GetMessage(msg,0,0,0);
cin.get();
}