/// <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); }
///// <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 IntPtr hWnd = Win32.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 != hWnd) WindowHighlighter.Refresh(_hPreviousWindow); // if we didn't find a window.. that's pretty hard to imagine. lol if (hWnd == IntPtr.Zero) { textBox_class_name.Text = null; } else { // save the window we're over _hPreviousWindow = hWnd; // class if (Win32.GetParent(hWnd) == (IntPtr)0) { textBox_class_name.Text = this.GetClassName(hWnd); } else { textBox_class_name.Text = this.GetClassName(Win32.GetParent(hWnd)); } Win32.Rect rc = new Win32.Rect(); Win32.GetWindowRect(hWnd, ref rc); // highlight the window WindowHighlighter.Highlight(hWnd); } } catch (Exception ex) { Debug.WriteLine(ex); } }
///// <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 IntPtr hWnd = Win32.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 != 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; textBox_class_name.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}", hWnd.ToInt32().ToString()); // class if (Win32.GetParent(hWnd) == (IntPtr)0) { textBox_class_name.Text = this.GetClassName(hWnd); } else { textBox_class_name.Text = this.GetClassName(Win32.GetParent(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); } }
/// <summary> /// Handles all mouse move messages sent to the Spy Window /// </summary> private void HandleMouseMovements() { if (!_capturing) return; try { IntPtr hWnd = Win32.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 != hWnd) WindowHighlighter.Refresh(_hPreviousWindow); if (hWnd == IntPtr.Zero) { textBox_class_name.Text = null; } else if (textBox_class_name.ReadOnly == false) { // save the window we're over _hPreviousWindow = hWnd; // class if (Win32.GetParent(hWnd) == (IntPtr)0) { textBox_class_name.Text = this.GetClassName(hWnd); } else { textBox_class_name.Text = this.GetClassName(Win32.GetParent(hWnd)); } Win32.Rect rc = new Win32.Rect(); Win32.GetWindowRect(hWnd, ref rc); // highlight the window WindowHighlighter.Highlight(hWnd); } } catch (Exception ex) { Debug.WriteLine(ex); } }