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; }
// default hook filter function internal int CoreHookProc(int code, IntPtr wParam, IntPtr lParam) { if (code < 0) { return(Win32.Function.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(Win32.Function.CallNextHookEx(hHook, code, wParam, lParam)); }
// handles the hook event private void CbtHookInvoked(object sender, HookEventArgs e) { // handle hook events (only a few of available actions) switch (e.code) { case Win32.Const.HCBT_CREATEWND: HandleCreateWndEvent(e.wParam, e.lParam); break; case Win32.Const.HCBT_DESTROYWND: HandleDestroyWndEvent(e.wParam, e.lParam); break; case Win32.Const.HCBT_ACTIVATE: HandleActivateEvent(e.wParam, e.lParam); break; } return; }