public bool StartHook() { IntPtr InstallHook = (IntPtr)(4194304); if (this.mouseHandler == IntPtr.Zero) { this.m_MouseHookProcedure = new HOOKPROCEDURE(MouseHookProcedure); this.mouseHandler = (IntPtr)SetWindowsHookEx(WH_MOUSE_LL, m_MouseHookProcedure, InstallHook, 0); if (this.mouseHandler == IntPtr.Zero) { //释放钩子 this.UnInstallHook(); return(false); } } return(true); }
//声明一个钩子函数 public static extern int SetWindowsHookEx(int HookType, HOOKPROCEDURE methodAddress, IntPtr handler, int dwThreadId);