SetWindowsHookEx UnhookWindowsHookEx Hook

HHOOK s_hHook;
int s_count = 0;
LRESULT CALLBACK CallWndRetProc( int nCode, WPARAM wParam, LPARAM lParam )
{
 if( nCode < 0 )
  return CallNextHookEx( s_hHook, nCode, wParam, lParam );
 CWPRETSTRUCT* pMsgInfo = ( CWPRETSTRUCT* )lParam;
 if( pMsgInfo->message == WM_ACTIVATE )
 {
  s_count++;
  TRACE("Activate: %d\n", s_count);
  TRACE("wParam: %d\n", pMsgInfo->wParam);
  TRACE("lParam: %d\n", pMsgInfo->lParam);
 }
 return CallNextHookEx( s_hHook, nCode, wParam, lParam );
}
static void Hook(CWnd* pWnd)
{
 if (!pWnd)
  return;
 HWND hParent = pWnd->GetSafeHwnd();
 DWORD dwThreadId = GetWindowThreadProcessId(hParent, NULL);
 HINSTANCE hInstance = AfxGetInstanceHandle();
 s_hHook = SetWindowsHookEx(WH_CALLWNDPROCRET, (HOOKPROC )CallWndRetProc,  hInstance, dwThreadId);
}
static void Unhook()
{
 if(s_hHook)
 {
  UnhookWindowsHookEx(s_hHook);
  s_hHook = NULL;
 }
}

你可能感兴趣的:(职场,hook,休闲)