Esempio n. 1
0
 protected virtual void OnMouseAction(MouseActionEventArgs e)
 {
     if (MouseAction != null)
     {
         // Invokes the delegates.
         MouseAction(this, e);
     }
 }
Esempio n. 2
0
        // Local mouse action event handler
        public void MouseAction(object sender, MouseActionEventArgs e)
        {
            Form1 form = (Form1)sender;
            DataGridViewRowCollection rows = form.dataGridView1.Rows;

            rows[form.index].Cells[1].Value = e.point.x;
            rows[form.index].Cells[2].Value = e.point.y;

            switch (e.mouseMessage)
            {
            case MouseMessages.WM_MOUSEMOVE:
                if (form.isNewRow)
                {
                    rows[form.index].Cells[0].Value = "Move";
                    form.isNewRow = false;
                }

                // Exits the global low level mouse hook, calls GC.Collect() actively, and then reenters a new hook
                form.SetHook(Form1.WH_MOUSE_LL);
                return;

            case MouseMessages.WM_LBUTTONDOWN:
                rows[form.index].Cells[0].Value = "Left Button Down";
                break;

            case MouseMessages.WM_RBUTTONDOWN:
                rows[form.index].Cells[0].Value = "Right Button Down";
                break;

            case MouseMessages.WM_LBUTTONUP:
                rows[form.index].Cells[0].Value = "Left Button Up";
                break;

            case MouseMessages.WM_RBUTTONUP:
                rows[form.index].Cells[0].Value = "Right Button Up";
                break;
            }

            Window win = new Tool().getWindow(e.hWnd, e.point);

            if (win != null)
            {
                //high light window's fame
                switch (e.mouseMessage)
                {
                case MouseMessages.WM_LBUTTONDOWN:
                case MouseMessages.WM_RBUTTONDOWN:
                    drawFrame(win);
                    lastWin = win;
                    break;

                case MouseMessages.WM_LBUTTONUP:
                case MouseMessages.WM_RBUTTONUP:
                    drawFrame(lastWin);

                    if (lastWin.hWnd != win.hWnd)
                    {
                        drawFrame(win);
                        Thread thd = new Thread(drawFrame);
                        thd.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(Form1.WH_MOUSE_LL);

                if (!form.windows.ContainsKey(win.hWnd))
                {
                    form.windows.Add(win.hWnd, win);
                }
                rows[form.index].Cells[3].Value = win.hWnd.ToString();

                form.dataGridView1.ClearSelection();
                rows[form.index++].Cells[3].Selected = true;
                form.isNewRow = true;
                if (form.index >= form.dataGridView1.Rows.Count)
                {
                    form.StopTracking_Click(null, null);
                }

                if (!form.splitContainer1.Panel2Collapsed)
                {
                    form.showWindowProperties(win.hWnd);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        ///  Mouse event hook callback
        /// </summary>
        /// <param name="nCode"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        private 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 = 0;
                switch ((MouseMessages)wParam)
                {
                case MouseMessages.WM_MOUSEMOVE:
                case MouseMessages.WM_LBUTTONDOWN:
                case MouseMessages.WM_RBUTTONDOWN:
                case MouseMessages.WM_LBUTTONUP:
                case MouseMessages.WM_RBUTTONUP:
                    mouseMessage = (MouseMessages)wParam;
                    break;

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

                IntPtr hWnd = IntPtr.Zero;
                if (mouseMessage != MouseMessages.WM_MOUSEMOVE)
                { // over form1
                    IntPtr hOwner = tool.getRootOwner(point, out hWnd);
                    if (hOwner == Handle)
                    {
                        // The event happend on Form1, treat it as a mouse move event.
                        mouseMessage = MouseMessages.WM_MOUSEMOVE;
                        // Allow buttons on Form1 to receive clicking immediately.
                        this.Activate();
                    }
                }

                int nowMs = DateTime.Now.Millisecond;
                if (mouseMessage == MouseMessages.WM_MOUSEMOVE &&
                    nowMs - refTimeMs < 200 && nowMs > refTimeMs)
                {
                    // Filter out the mouse move events which happend in 200 ms.
                    return(User32.CallNextHookEx(mouseHookID, nCode, (IntPtr)mouseMessage, lParam));
                }

                // Prepare parementers and raise a local mouse event
                MouseActionEventArgs e = new MouseActionEventArgs(mouseMessage, point, hWnd);
                OnMouseAction(e);

                // Change reference time
                refTimeMs = DateTime.Now.Millisecond;
            }
            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));
        }
Esempio n. 4
0
 public MacroEventArgs(MouseActionEventArgs e)
 {
     this.name  = e.name;
     this.point = e.point;
     this.hWnd  = e.hWnd;
 }