private void Form1_FormClosed(object sender, FormClosedEventArgs e) { //卸载钩子 CWin32Api.UnhookWindowsHookEx(hookHandle); }
private void Form1_Load(object sender, EventArgs e) { hookproc = new CWin32Api.HookProc(MouseEvent); //为委托变量赋值(方法名) hookHandle = CWin32Api.SetWindowsHookEx(MOUSEHOOK, hookproc, IntPtr.Zero, 0); //安装钩子 }