Пример #1
0
        /// <summary>
        /// Highlights the specified window just like Spy++
        /// </summary>
        /// <param name="hWnd"></param>
        public static void Highlight(IntPtr hWnd)
        {
            const float penWidth = 3;

            Win32.Rect rc = new Win32.Rect();
            Win32.GetWindowRect(hWnd, ref rc);

            IntPtr hDC = Win32.GetWindowDC(hWnd);

            if (hDC != IntPtr.Zero)
            {
                using (Pen pen = new Pen(Color.Black, penWidth))
                {
                    using (Graphics g = Graphics.FromHdc(hDC))
                    {
                        g.DrawRectangle(pen, 0, 0, rc.right - rc.left - (int)penWidth, rc.bottom - rc.top - (int)penWidth);
                    }
                }
            }
            Win32.ReleaseDC(hWnd, hDC);
        }
Пример #2
0
        /// <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
            {
                IntPtr hWnd = IntPtr.Zero;
                _parentHandle = Win32.WindowFromPoint(Cursor.Position);
                hWnd          = _parentHandle;
                // capture the window under the cursor's position
                if (_childSearch)
                {
                    //Point ClientPoint = Cursor.Position;
                    //Win32.ScreenToClient(_parentHandle,out ClientPoint);
                    //if (_realOnly)
                    //{
                    //    _childHandle = Win32.RealChildWindowFromPoint(_parentHandle, ClientPoint);
                    //}
                    //else
                    //{
                    //_childHandle = Win32.ChildWindowFromPoint(_parentHandle, ClientPoint);
                    _childHandle = GetChildMost(_parentHandle, Cursor.Position);
                    //}
                    hWnd = _childHandle;
                }

                if (hWnd == IntPtr.Zero)
                {
                    return;
                }

                // 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 != hWnd)
                {
                    WindowHighlighter.Refresh(_hPreviousWindow);
                }

                // if we didn't find a window.. that's pretty hard to imagine. lol
                if (hWnd == IntPtr.Zero)
                {
                    _textBoxHandle.Text = null;
                    _textBoxClass.Text  = null;
                    _textBoxText.Text   = null;
                    _textBoxStyle.Text  = null;
                    _textBoxRect.Text   = null;
                }
                else
                {
                    // save the window we're over
                    _hPreviousWindow = hWnd;

                    // handle
                    _textBoxHandle.Text = string.Format("{0}", _parentHandle.ToInt32().ToString());

                    // class
                    _textBoxClass.Text = this.GetClassName(hWnd);

                    // caption
                    _textBoxText.Text = this.GetWindowText(hWnd);

                    Win32.Rect rc = new Win32.Rect();
                    Win32.GetWindowRect(hWnd, ref rc);

                    // rect
                    _textBoxRect.Text = string.Format("[{0} x {1}], ({2},{3})-({4},{5})", rc.right - rc.left, rc.bottom - rc.top, rc.left, rc.top, rc.right, rc.bottom);

                    // highlight the window
                    WindowHighlighter.Highlight(hWnd);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }