/// <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 Win32.SetCapture(this.Handle); // set the mouse cursor to our finder cursor Cursor.Current = _cursorFinder; // change the image to the finder gone image _pictureBox.Image = _finderGone; } // otherwise we're supposed to release the mouse capture else { // so release it Win32.ReleaseCapture(); // put the default cursor back Cursor.Current = _cursorDefault; // change the image back to the finder at home image _pictureBox.Image = _finderHome; // and finally refresh any window that we were highlighting if (_hPreviousWindow != IntPtr.Zero) { WindowHighlighter.Refresh(_hPreviousWindow); //_hPreviousWindow = IntPtr.Zero; } } // save our capturing state _capturing = captured; }
/// <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); } }