예제 #1
0
        }        //end GetClassName

        /// <summary>
        /// Captures or releases the mouse
        /// </summary>
        /// <param name="captured"></param>
        private void CaptureMouse(bool captured)
        {
            // if we're supposed to capture the window
            if (captured)
            {
                // capture the mouse movements and send them to ourself
                User32.SetCapture(this.Handle);

                // set the mouse cursor to our finder cursor
                Cursor.Current = _cursorFinder;

                // change the image to the finder gone image
                m_picFinder.Image = _finderGone;
            }            //end if
            // otherwise we're supposed to release the mouse capture
            else
            {
                // so release it
                User32.ReleaseCapture();

                // put the default cursor back
                Cursor.Current = _cursorDefault;

                // change the image back to the finder at home image
                m_picFinder.Image = _finderHome;

                // and finally refresh any window that we were highlighting
                if (_hPreviousWindow != IntPtr.Zero)
                {
                    WindowHighlighter.Refresh(_hPreviousWindow);
                    _hPreviousWindow = IntPtr.Zero;
                }        //end if
            }            //end else

            // save our capturing state
            _capturing = captured;
        }        //end CaptureMouse
예제 #2
0
        }        //end CaptureMouse

        /// <summary>
        /// Handles all mouse move messages sent to the Spy Window
        /// </summary>
        private void HandleMouseMovements()
        {
            // if we're not capturing, then bail out
            if (!_capturing)
            {
                return;
            }

            try
            {
                // capture the window under the cursor's position
                _hCurrentWindow = User32.WindowFromPoint(Cursor.Position);

                // if the window we're over, is not the same as the one before, and we had one before, refresh it
                if (_hPreviousWindow != IntPtr.Zero && _hPreviousWindow != _hCurrentWindow)
                {
                    WindowHighlighter.Refresh(_hPreviousWindow);
                }

                // if we didn't find a window.. that's pretty hard to imagine. lol
                if (_hCurrentWindow == IntPtr.Zero)
                {
                    m_txtHandle.Text  = "";
                    m_txtClass.Text   = "";
                    m_txtCaption.Text = "";
                    m_txtStyle.Text   = "";
                    m_txtRect.Text    = "";
                }                //end if
                else
                {
                    // save the window we're over
                    _hPreviousWindow = _hCurrentWindow;

                    m_txtProcess.Text = GetProcessPath(_hCurrentWindow);

                    m_txtHandle.Text = string.Format("{0}", _hCurrentWindow.ToInt32().ToString());

                    m_txtClass.Text = this.GetClassName(_hCurrentWindow);

                    m_txtCaption.Text = User32.GetWindowText(_hCurrentWindow);

                    if (m_txtClass.Text == "Edit" || m_txtCaption.Text == "")
                    {
                        m_txtCaption.Text = User32.GetText(_hCurrentWindow);
                    }                    //end if

                    User32.GetWindowRect(_hCurrentWindow, out User32.RECT rc);
                    User32EnumChildWindows.EnumChildWindows(_hCurrentWindow, m_txtCaption.Text);

                    // rect
                    m_txtRect.Text = string.Format(
                        "[{0} x {1}], ({2})",
                        rc.Right - rc.Left, rc.Bottom - rc.Top, rc.ToString());

                    // highlight the window
                    WindowHighlighter.Highlight(_hCurrentWindow);
                }        //end else
            }            //end try
            catch (Exception err)
            {
                Debug.WriteLine("HandleMouseMovements: " + err);
                FormClipboard.TraceLn(false, "FormSpyWindow", "HandleMouseMovements",
                                      "Error: {0}", err.Message);
            }    //end catch
        }        //end HandleMouseMovements