public FrmWindowPicker() { InitializeComponent(); _tool = new Tool(); _mouseHookProc = Mouse_HookCallback; SetHook(WH_KEYBOARD_LL); MouseActionProcess mouseActionProcess = new MouseActionProcess(); // set local mouse event handler MouseAction += mouseActionProcess.MouseAction; }
// Local mouse action event handler public void MouseAction(object sender, MouseActionEventArgs e) { FrmWindowPicker form = (FrmWindowPicker) sender; Window win = new Tool().getWindow(e.hWnd, e.point); if (win != null) { //high light window's fame switch (e.mouseMessage) { case MouseMessages.WM_LBUTTONDOWN: drawFrame(win); lastWin = win; break; case MouseMessages.WM_LBUTTONUP: drawFrame(lastWin); if (lastWin.hWnd != win.hWnd) { drawFrame(win); Thread thd = new Thread(drawFrame) {Name = "delay"}; thd.Start(win); } lastWin = null; break; } // Exits the global low level mouse hook, calls GC.Collect() actively, and then reenters a new hook form.SetHook(FrmWindowPicker.WH_MOUSE_LL); form.ShowWindowProperties(win); form.PickedWindow = win; } }