示例#1
0
        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);
        }
示例#2
0
        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));
        }
示例#3
0
 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;
 }
示例#4
0
 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;
 }
示例#5
0
        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);
            }
        }
示例#6
0
 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;
 }
示例#7
0
        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;
        }