[C++] Windows Message Hooking for your own Process
WNDPROC pOrigProc;
LRESULT CALLBACK HookWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_LBUTTONDOWN:
MessageBox(NULL, TEXT("WM_LBUTTONDOWN"), TEXT("WM_LBUTTONDOWN"), MB_OK);
break;
}
return CallWindowProc(pOrigProc, hwnd, uMsg, wParam, lParam);
}
void SetHook(HWND hwnd)
{
if (pOrigProc != NULL)
return;
pOrigProc = (WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (LONG)HookWndProc);
if (!pOrigProc)
{
printf("SWL Error: %d\n", GetLastError());
}
else
{
printf("Successfully hooked the Window Callback!\n");
}
}