コード例 #1
0
        /// <summary>
        /// Hooks the hook.
        /// </summary>
        public virtual void StartHook()
        {
            if (hooked)
            {
                return;
            }
            IntPtr delegt = Marshal.GetFunctionPointerForDelegate(managedDelegate);

            if (global)
            {
                if (type == HookType.WH_KEYBOARD_LL || type == HookType.WH_MOUSE_LL)
                {
                    hHook = SetWindowsHookEx(type, delegt, getMainModuleHandle(), 0);
                }
                else
                {
                    ednw = EventDispatchingNativeWindow.Instance;
                    ednw.EventHandler += new WndProcEventHandler(hookEventHandler);
                    hHook              = AllocHookWrapper(type, ednw.Handle);
                }
            }
            else
            {
                hHook = SetWindowsHookEx(type, delegt, IntPtr.Zero, getThreadID());
            }
            if (hHook == IntPtr.Zero)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
            hooked = true;
        }
コード例 #2
0
        public void StartHook()
        {
            if (hooked)
            {
                return;
            }

            ednw = EventDispatchingNativeWindow.Instance;
            ednw.EventHandler += clipboardEventHandler;
            hWnd     = ednw.Handle;
            nextHWnd = SetClipboardViewer(hWnd);
            hooked   = true;
        }