GetWindowBounds() public static method

public static GetWindowBounds ( IntPtr hWnd ) : System.Windows.Rect
hWnd System.IntPtr
return System.Windows.Rect
Esempio n. 1
0
        void UpdateEditStateImpl(bool moveOnly = false)
        {
            Logger.WindowWatcher.Verbose($"> FormulaEdit UpdateEditState - Thread {Thread.CurrentThread.ManagedThreadId}");
            Logger.WindowWatcher.Verbose($"FormulaEdit UpdateEditState - Focus: {_formulaEditFocus} Window: {(_formulaEditFocus == FormulaEditFocus.FormulaBar ? _hwndFormulaBar : _hwndInCellEdit)}");

            IntPtr hwnd          = IntPtr.Zero;
            bool   prefixChanged = false;

            if (_formulaEditFocus == FormulaEditFocus.FormulaBar)
            {
                hwnd = _hwndFormulaBar;
            }
            else if (_formulaEditFocus == FormulaEditFocus.InCellEdit)
            {
                hwnd = _hwndInCellEdit;
            }
            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("#### FormulaEditWatcher - No Window " + Environment.StackTrace);
            }

            if (hwnd != IntPtr.Zero)
            {
                EditWindowBounds = Win32Helper.GetWindowBounds(hwnd);

                if (!IsEditingFormula)
                {
                    IntPtr hwndTopLevel = Win32Helper.GetRootAncestor(hwnd);
                    InstallLocationMonitor(hwndTopLevel);
                    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 (or more direct) notification...?
            if (moveOnly && !prefixChanged)
            {
                StateChanged?.Invoke(this, new StateChangeEventArgs(StateChangeType.Move));
            }
            else
            {
                OnStateChanged(StateChangeType.Multiple);
            }
        }
        void UpdateSelectedItem()
        {
            if (_hwndPopupList == IntPtr.Zero)
            {
                Logger.WindowWatcher.Verbose("PopupList UpdateSelectedItem ignored: PopupList is null");
                return;
            }

            if (!IsVisible)
            {
                if (_selectedItemIndex == -1 &&
                    SelectedItemText == string.Empty &&
                    SelectedItemBounds == Rect.Empty)
                {
                    // Don't change anything, or fire an updated event
                    return;
                }

                // Set to the way things should be when not visible, and fire an updated event
                _selectedItemIndex = -1;
                SelectedItemText   = string.Empty;
                SelectedItemBounds = Rect.Empty;
                ListBounds         = Rect.Empty;
            }
            else
            {
                string text;
                Rect   itemBounds;
                var    hwndListView = Win32Helper.GetFirstChildWindow(_hwndPopupList);
                ListBounds = Win32Helper.GetWindowBounds(_hwndPopupList);

                _selectedItemIndex = Win32Helper.GetListViewSelectedItemInfo(hwndListView, out text, out itemBounds);
                if (string.IsNullOrEmpty(text))
                {
                    // We (unexpectedly) failed to get information about the selected item - not sure this is a problem
                    Logger.WindowWatcher.Info("PopupList UpdateSelectedItem - IsVisible but GetListViewSelectedItemInfo failed ");
                    _selectedItemIndex = -1;
                    SelectedItemText   = string.Empty;
                    SelectedItemBounds = Rect.Empty;
                    ListBounds         = Rect.Empty;
                }
                else
                {
                    // Normal case - all is OK
                    itemBounds.Offset(ListBounds.Left, ListBounds.Top);
                    SelectedItemBounds = itemBounds;
                    SelectedItemText   = text;
                }
            }
            OnSelectedItemChanged();
        }
 // Runs on our automation thread
 void _windowWatcher_FormulaEditLocationChanged(object sender, EventArgs e)
 {
     if (IsVisible && _selectedItemIndex != -1 && _hwndPopupList != IntPtr.Zero)
     {
         string text;
         Rect   itemBounds;
         var    hwndListView = Win32Helper.GetFirstChildWindow(_hwndPopupList);
         ListBounds = Win32Helper.GetWindowBounds(_hwndPopupList);
         Win32Helper.GetListViewSelectedItemInfo(hwndListView, out text, out itemBounds);
         itemBounds.Offset(ListBounds.Left, ListBounds.Top);
         SelectedItemBounds = itemBounds;
         OnSelectedItemChanged();
     }
 }
Esempio n. 4
0
        void UpdateSelectedItem()
        {
            if (_hwndPopupList == IntPtr.Zero)
            {
                Logger.WindowWatcher.Verbose($"PopupList UpdateSelectedItem ignored: PopupList is null");
                return;
            }

            if (!IsVisible)
            {
                if (_selectedItemIndex == -1 &&
                    SelectedItemText == string.Empty &&
                    SelectedItemBounds == Rect.Empty)
                {
                    // Don't change anything, or fire an updated event
                    return;
                }

                // Set to the way things should be when not visible, and fire an updated event
                _selectedItemIndex = -1;
                SelectedItemText   = string.Empty;
                SelectedItemBounds = Rect.Empty;
                ListBounds         = Rect.Empty;
            }
            else
            {
                string text;
                Rect   itemBounds;
                var    hwndListView = Win32Helper.GetFirstChildWindow(_hwndPopupList);
                ListBounds = Win32Helper.GetWindowBounds(_hwndPopupList);

                _selectedItemIndex = Win32Helper.GetListViewSelectedItemInfo(hwndListView, out text, out itemBounds);
                itemBounds.Offset(ListBounds.Left, ListBounds.Top);
                SelectedItemBounds = itemBounds;
                SelectedItemText   = text;
            }
            OnSelectedItemChanged();
        }