internal bool InternalPostFilterMessage(HookInfo hInfo, int Msg, Control wnd, IntPtr HWnd, IntPtr WParam, IntPtr LParam) { bool result = false; for (int n = hInfo.HookControllers.Count - 1; n >= 0; n--) { IHookController ctrl = hInfo.HookControllers[n] as IHookController; result |= ctrl.InternalPostFilterMessage(Msg, wnd, HWnd, WParam, LParam); if (Msg == 0x2) { if (ctrl.OwnerHandle == HWnd) { RemoveController(ctrl); } } } return(result); }
protected int GetMessageHook(int ncode, IntPtr wParam, IntPtr lParam) { HookInfo hInfo = GetInfoByThread(); API_MSG hookStr = (API_MSG)Marshal.PtrToStructure(lParam, typeof(API_MSG)); if (!hInfo.inHook && lParam != IntPtr.Zero) { try { hInfo.inHook = true; InternalGetMessage(ref hookStr); } finally { hInfo.inHook = false; } } return(CallNextHookEx(hInfo.wndHookHandle, ncode, wParam, lParam)); }
internal void InstallHook(HookInfo hInfo) { if (hInfo.wndHookHandle != IntPtr.Zero) return; hInfo.mouseHookProc = new Hook(MouseHook); hInfo.wndHookProc = new Hook(WndHook); hInfo.getMessageHookProc = new Hook(GetMessageHook); hInfo.wndHookHandle = SetWindowsHookEx(4, hInfo.wndHookProc, 0, hInfo.ThreadId); hInfo.mouseHookHandle = SetWindowsHookEx(7, hInfo.mouseHookProc, 0, hInfo.ThreadId); hInfo.getMessageHookHandle = IntPtr.Zero; }
protected virtual HookInfo GetInfoByThread() { int thId = CurrentThread; HookInfo hInfo = HookHash[thId] as HookInfo; if (hInfo == null) { hInfo = new HookInfo();//(this); HookHash[thId] = hInfo; } return hInfo; }
internal void RemoveHook(HookInfo hInfo, bool disposing) { if (hInfo.wndHookHandle != IntPtr.Zero) { UnhookWindowsHookEx(hInfo.wndHookHandle); hInfo.wndHookHandle = IntPtr.Zero; hInfo.wndHookProc = null; hInfo.getMessageHookHandle = IntPtr.Zero; hInfo.getMessageHookProc = null; UnhookWindowsHookEx(hInfo.mouseHookHandle); hInfo.mouseHookHandle = IntPtr.Zero; hInfo.mouseHookProc = null; HookHash.Remove(hInfo.ThreadId); } }
internal bool InternalPreFilterMessage(HookInfo hInfo, int Msg, Control wnd, IntPtr HWnd, IntPtr WParam, IntPtr LParam) { bool result = false; for (int n = 0; n < hInfo.HookControllers.Count; n++) { IHookController ctrl = hInfo.HookControllers[n] as IHookController; result |= ctrl.InternalPreFilterMessage(Msg, wnd, HWnd, WParam, LParam); } return result; }
internal bool InternalPostFilterMessage(HookInfo hInfo, int Msg, Control wnd, IntPtr HWnd, IntPtr WParam, IntPtr LParam) { bool result = false; for (int n = hInfo.HookControllers.Count - 1; n >= 0; n--) { IHookController ctrl = hInfo.HookControllers[n] as IHookController; result |= ctrl.InternalPostFilterMessage(Msg, wnd, HWnd, WParam, LParam); if (Msg == 0x2) { if (ctrl.OwnerHandle == HWnd) { RemoveController(ctrl); } } } return result; }