GetClientCursorPos() public static method

public static GetClientCursorPos ( IntPtr hWnd ) : Point
hWnd System.IntPtr
return System.Drawing.Point
Ejemplo n.º 1
0
        void UpdateEditState(bool moveOnly = false)
        {
            _syncContext.Post(delegate
            {
                // TODO: This is not right yet - the list box might have the focus...
                AutomationElement focused;
                try
                {
                    focused = AutomationElement.FocusedElement;
                }
                catch (ArgumentException aex)
                {
                    Debug.Print("!!! ERROR: Failed to get Focused Element: " + aex.ToString());
                    // Not sure why I get this - sometimes with startup screen
                    return;
                }
                if (_formulaBar != null && _formulaBar.Equals(focused))
                {
                    EditWindowBounds = (Rect)_formulaBar.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);
                    IntPtr hwnd      = (IntPtr)(int)_formulaBar.GetCurrentPropertyValue(AutomationElement.NativeWindowHandleProperty);
                    var pt           = Win32Helper.GetClientCursorPos(hwnd);
                    CaretPosition    = new Point(pt.X, pt.Y);
                }
                else if (_inCellEdit != null && _inCellEdit.Equals(focused))
                {
                    EditWindowBounds = (Rect)_inCellEdit.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);
                    IntPtr hwnd      = (IntPtr)(int)_inCellEdit.GetCurrentPropertyValue(AutomationElement.NativeWindowHandleProperty);
                    var pt           = Win32Helper.GetClientCursorPos(hwnd);
                    CaretPosition    = new Point(pt.X, pt.Y);
                }
                else
                {
                    // CurrentFormula = null;
                    CurrentPrefix = null;
                    Debug.Print("Don't have a focused text box to update.");
                }

                // As long as we have an InCellEdit, we are editing the formula...
                IsEditingFormula = (_inCellEdit != null);

                // TODO: Smarter notification...?
                StateChanged(this, new StateChangeEventArgs(moveOnly ? StateChangeTypeEnum.Move : StateChangeTypeEnum.Undefined));
            }, null);
        }
Ejemplo n.º 2
0
        // Switches to our Automation thread, updates current state and raises StateChanged event
        void UpdateEditState(bool moveOnly = false)
        {
            Logger.WindowWatcher.Verbose("> FormulaEdit UpdateEditState - Posted");
            _syncContextAuto.Post(moveOnlyObj =>
            {
                Logger.WindowWatcher.Verbose($"FormulaEdit UpdateEditState - Focus: {_formulaEditFocus}");
                //// TODO: This is not right yet - the list box might have the focus... ?
                //AutomationElement focused;
                //try
                //{
                //    focused = AutomationElement.FocusedElement;
                //}
                //catch (ArgumentException aex)
                //{
                //    Debug.Print($"!!! ERROR: Failed to get Focused Element: {aex}");
                //    // Not sure why I get this - sometimes with startup screen
                //    return;
                //}
                AutomationElement focusedEdit = null;
                bool prefixChanged            = false;
                if (_formulaEditFocus == FormulaEditFocus.FormulaBar)
                {
                    focusedEdit = _formulaBar;
                }
                else if (_formulaEditFocus == FormulaEditFocus.InCellEdit)
                {
                    focusedEdit = _inCellEdit;
                }
                else
                {
                    // Neither have the focus, so we don't update anything
                    Logger.WindowWatcher.Verbose("FormulaEdit UpdateEditState End formula editing");
                    CurrentPrefix = null;
                    if (IsEditingFormula)
                    {
                        UninstallLocationMonitor();
                    }
                    IsEditingFormula = false;
                    prefixChanged    = true;
                    // Debug.Print("Don't have a focused text box to update.");
                }

                if (focusedEdit != null)
                {
                    EditWindowBounds = (Rect)focusedEdit.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);
                    IntPtr hwnd      = (IntPtr)(int)focusedEdit.GetCurrentPropertyValue(AutomationElement.NativeWindowHandleProperty);

                    var pt = Win32Helper.GetClientCursorPos(hwnd);

                    if (!IsEditingFormula)
                    {
                        InstallLocationMonitor(GetTopLevelWindow(focusedEdit));
                    }
                    IsEditingFormula = true;

                    var newPrefix = XlCall.GetFormulaEditPrefix();      // What thread do we have to use here ...?
                    if (CurrentPrefix != newPrefix)
                    {
                        CurrentPrefix = newPrefix;
                        prefixChanged = true;
                    }
                    Logger.WindowWatcher.Verbose($"FormulaEdit UpdateEditState Formula editing: CurrentPrefix {CurrentPrefix}, EditWindowBounds: {EditWindowBounds}");
                }

                // TODO: Smarter notification...?
                if ((bool)moveOnlyObj && !prefixChanged)
                {
                    StateChanged?.Invoke(this, new StateChangeEventArgs(StateChangeType.Move));
                }
                else
                {
                    OnStateChanged(new StateChangeEventArgs(StateChangeType.Multiple));
                }
            }, moveOnly);
        }