示例#1
0
        /// <summary>
        /// 安装Window钩子到主线程
        /// </summary>
        /// <param name="hookType">钩子类型</param>
        /// <param name="callBack">回调函数</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        /// <returns></returns>
        public static bool HookWindow(WinHookType hookType, WinHookCallback callBack)
        {
            if (callBack == null)
            {
                throw new ArgumentNullException("callBack");
            }

            if (Enum.IsDefined(typeof(WinHookType), hookType) == false)
            {
                throw new ArgumentException("hookType的值无效");
            }

            var callBackPointer = Marshal.GetFunctionPointerForDelegate(callBack);
            var state           = Extern.HookWindow((int)hookType, callBackPointer);

            if (state == true)
            {
                ReferenceTable.AddRef(callBack);
            }
            return(state);
        }
示例#2
0
 private static extern int SetWindowsHookEx(WinHookType idHook,
                                            WinHookProcedure lpfn,
                                            IntPtr hMod,
                                            int dwThreadId);
示例#3
0
 /// <summary>
 /// 反安装Window钩子
 /// </summary>
 /// <param name="hookType">钩子类型</param>
 public static void UnHookWindow(WinHookType hookType)
 {
     Extern.UnHookWindow((int)hookType);
 }
示例#4
0
 internal static extern int CallNextHookEx(WinHookType idHook, int nCode, IntPtr wParam, IntPtr lParam);