// handles the hook event private void CbtHookInvoked(object sender, HookEventArgs e) { // handle hook events (only a few of available actions) switch ((CbtHookAction)e.code) { case CbtHookAction.HCBT_CREATEWND: HandleCreateWndEvent(e.wParam, e.lParam); break; case CbtHookAction.HCBT_DESTROYWND: HandleDestroyWndEvent(e.wParam, e.lParam); break; case CbtHookAction.HCBT_ACTIVATE: HandleActivateEvent(e.wParam, e.lParam); break; } return; }
// default hook filter function internal int CoreHookProc(int code, IntPtr wParam, IntPtr lParam) { if (code < 0) return CallNextHookEx(hHook, code, wParam, lParam); // let clients determine what to do HookEventArgs e = new HookEventArgs(code, wParam, lParam); OnHookInvoke(e); // yield to the next hook in the chain return CallNextHookEx(hHook, code, wParam, lParam); }
internal void OnHookInvoke(HookEventArgs e) { if (HookInvoke != null) HookInvoke(this, e); }
// handles the hook event private void WndProcRetHookInvoked(object sender, HookEventArgs e) { WndProcRetEventArgs wpe = new WndProcRetEventArgs(e.wParam, e.lParam); if ((hWndHooked == IntPtr.Zero || wpe.cw.hwnd == hWndHooked) && WndProcRet != null) WndProcRet(this, wpe); return; }