コード例 #1
0
        // 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;
            }
        }
コード例 #2
0
        /// <summary>
        ///  Mouse event hook callback
        /// </summary>
        /// <param name="nCode"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        public IntPtr Mouse_HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            try
            {
                if (nCode < 0) return User32.CallNextHookEx(_mouseHookId, nCode, wParam, lParam);

                POINT point = ((MSLLHOOKSTRUCT) Marshal.PtrToStructure(lParam, typeof (MSLLHOOKSTRUCT))).pt;

                MouseMessages mouseMessage;
                switch ((MouseMessages) wParam)
                {
                    case MouseMessages.WM_LBUTTONDOWN:
                    case MouseMessages.WM_LBUTTONUP:
                        mouseMessage = (MouseMessages) wParam;
                        break;

                    default:
                        // Do not process other events.
                        return User32.CallNextHookEx(_mouseHookId, nCode, wParam, lParam);
                }

                IntPtr hWnd;
                IntPtr hOwner = _tool.getRootOwner(point, out hWnd);

                // The event happend on window picker form, don't process it
                if (hOwner == Handle)
                {
                    // Allow buttons on window picker form to receive clicking immediately.
                    Activate();
                    Debug.Print("Ignoring Action!");
                }
                else
                {
                    // Prepare parementers and raise a local mouse event
                    MouseActionEventArgs e = new MouseActionEventArgs(mouseMessage, point, hWnd);
                    OnMouseAction(e);

                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(
                    "Error in private IntPtr Mouse_HookCallback(int nCode, IntPtr wParam, IntPtr lParam): " + e.Message);
            }
            return User32.CallNextHookEx(_mouseHookId, nCode, wParam, lParam);
        }
コード例 #3
0
 protected virtual void OnMouseAction(MouseActionEventArgs e)
 {
     if (MouseAction != null)
     {
         // Invokes the delegates.
         MouseAction(this, e);
     }
 }