Ejemplo n.º 1
0
        public static Point CorrectGetPosition(Visual relativeTo)
        {
            var w32Mouse = new NativeMethods.Win32Point();

            NativeMethods.GetCursorPos(ref w32Mouse);
            return(relativeTo.PointFromScreen(new Point(w32Mouse.X, w32Mouse.Y)));
        }
        // Returns a Proxy element corresponding to the specified screen coordinates.
        internal override ProxySimple ElementProviderFromPoint(int x, int y)
        {
            int x1 = x;
            int y1 = y;

            NativeMethods.Win32Rect rebarRect = new NativeMethods.Win32Rect();
            if (!Misc.GetWindowRect(_hwnd, ref rebarRect))
            {
                return(null);
            }

            if (x >= rebarRect.left && x <= rebarRect.right &&
                y >= rebarRect.top && y <= rebarRect.bottom)
            {
                x = x - rebarRect.left;
                y = y - rebarRect.top;

                NativeMethods.Win32Point pt = new NativeMethods.Win32Point(x, y);

                int BandID = getRebarBandIDFromPoint(pt);

                if (-1 != BandID)
                {
                    return(CreateRebarItem(BandID).ElementProviderFromPoint(x1, y1));
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        public static Point CorrectGetPosition()
        {
            var w32Mouse = new NativeMethods.Win32Point();

            NativeMethods.GetCursorPos(ref w32Mouse);
            return(new Point(w32Mouse.X, w32Mouse.Y));
        }
Ejemplo n.º 4
0
        ITextRangeProvider ITextProvider.RangeFromPoint(Point screenLocation)
        {
            // convert screen to client coordinates.
            // (Essentially ScreenToClient but MapWindowPoints accounts for window mirroring using WS_EX_LAYOUTRTL.)
            NativeMethods.Win32Point clientLocation = (NativeMethods.Win32Point)screenLocation;
            if (!Misc.MapWindowPoints(IntPtr.Zero, WindowHandle, ref clientLocation, 1))
            {
                return(null);
            }

            // we have to deal with the possibility that the coordinate is inside the window rect
            // but outside the client rect. in that case we just scoot it over so it is at the nearest
            // point in the client rect.
            NativeMethods.Win32Rect clientRect = new NativeMethods.Win32Rect();
            if (!Misc.GetClientRect(WindowHandle, ref clientRect))
            {
                return(null);
            }
            clientLocation.x = Math.Max(clientLocation.x, clientRect.left);
            clientLocation.x = Math.Min(clientLocation.x, clientRect.right);
            clientLocation.y = Math.Max(clientLocation.y, clientRect.top);
            clientLocation.y = Math.Min(clientLocation.y, clientRect.bottom);

            // get the character at those client coordinates
            int start = CharFromPosEx(clientLocation);

            return(new WindowsEditBoxRange(this, start, start));
        }
Ejemplo n.º 5
0
        // Returns a Proxy element corresponding to the specified screen coordinates.
        internal override ProxySimple ElementProviderFromPoint(int x, int y)
        {
            ProxySimple proxyElement = null;

            // Convert screen to client coords.
            NativeMethods.Win32Point pt = new NativeMethods.Win32Point(x, y);
            if (Misc.MapWindowPoints(System.IntPtr.Zero, _hwnd, ref pt, 1))
            {
                // GetClientRect
                NativeMethods.Win32Rect clientRect = new NativeMethods.Win32Rect();
                if (Misc.GetClientRect(_hwnd, ref clientRect))
                {
                    if (Misc.PtInRect(ref clientRect, pt.x, pt.y))
                    {
                        int column = (pt.x - _altTabInfo.ptStart.x) / _altTabInfo.cxItem;
                        int row    = (pt.y - _altTabInfo.ptStart.y) / _altTabInfo.cyItem;
                        if (column >= 0 && column < Columns && row >= 0 && row < Rows)
                        {
                            proxyElement = CreateAltTabItem(ItemIndex(row, column));
                        }
                    }
                }
            }
            if (proxyElement == null)
            {
                proxyElement = base.ElementProviderFromPoint(x, y);
            }


            return(proxyElement);
        }
Ejemplo n.º 6
0
        public static Point GetMousePosition()
        {
            var mouse = new NativeMethods.Win32Point();

            NativeMethods.GetCursorPos(ref mouse);
            return(new Point(mouse.X, mouse.Y));
        }
        // Same as clicking on an hyperlink
        void IInvokeProvider.Invoke()
        {
            // Check that button can be clicked.
            //
            // This state could change anytime.
            //

            // Make sure that the control is enabled
            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
            {
                throw new ElementNotEnabledException();
            }

            if (!SafeNativeMethods.IsWindowVisible(_hwnd))
            {
                throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
            }

            Misc.SetFocus(_hwnd);

            NativeMethods.Win32Point pt = new NativeMethods.Win32Point();
            if (GetClickablePoint(out pt, false))
            {
                Misc.MouseClick(pt.x, pt.y);
            }
        }
        // ------------------------------------------------------
        //
        // Private Methods
        //
        // ------------------------------------------------------

        #region Private Methods

        private static bool ClickableInRect(IntPtr hwnd, ref NativeMethods.Win32Point pt, bool fRiAsInsideRect, ArrayList alIn, ArrayList alOut)
        {
            if (!SafeNativeMethods.IsWindowVisible(hwnd))
            {
                return(fRiAsInsideRect);
            }

            // Get the window rect. If this window has a width and it is effectivly invisible
            NativeMethods.Win32Rect rc = new NativeMethods.Win32Rect();

            if (!Misc.GetWindowRect(hwnd, ref rc))
            {
                return(fRiAsInsideRect);
            }

            if ((rc.right - rc.left) <= 0 || (rc.bottom - rc.top) <= 0)
            {
                return(fRiAsInsideRect);
            }

            // Try for transparency...
            if (fRiAsInsideRect)
            {
                int x = (rc.right + rc.left) / 2;
                int y = (rc.top + rc.bottom) / 2;

                try
                {
                    int lr = Misc.ProxySendMessageInt(hwnd, NativeMethods.WM_NCHITTEST, IntPtr.Zero, NativeMethods.Util.MAKELPARAM(x, y));

                    if (lr == NativeMethods.HTTRANSPARENT)
                    {
                        return(true);
                    }
                }
// PRESHARP: Warning - Catch statements should not have empty bodies
#pragma warning disable 6502
                catch (TimeoutException)
                {
                    // Ignore this timeout error.  Avalon HwndWrappers have a problem with this WM_NCHITTEST call sometimes.
                }
#pragma warning restore 6502
            }

            // Copy the output bits
            alIn.Clear();
            alIn.AddRange(alOut);

            CPRect rcp = new CPRect(ref rc, false);

            ClickablePoint.SplitRect(alIn, ref rcp, alOut, fRiAsInsideRect);
            if (!GetClickablePoint(alOut, out pt.x, out pt.y))
            {
                return(false);
            }

            return(true);
        }
        private unsafe int getRebarBandIDFromPoint(NativeMethods.Win32Point pt)
        {
            NativeMethods.RB_HITTESTINFO rbHitTestInfo = new NativeMethods.RB_HITTESTINFO();
            rbHitTestInfo.pt     = pt;
            rbHitTestInfo.uFlags = 0;
            rbHitTestInfo.iBand  = 0;

            return(XSendMessage.XSendGetIndex(_hwnd, NativeMethods.RB_HITTEST, IntPtr.Zero, new IntPtr(&rbHitTestInfo), Marshal.SizeOf(rbHitTestInfo.GetType())));
        }
Ejemplo n.º 10
0
        private void OnWindowMessage(uint messageId, IntPtr wParam, IntPtr lParam)
        {
            if (messageId != iconData.uCallbackMessage)
            {
                // Ignore messages not associated with this icon
                return;
            }

            switch (lParam.ToInt32())
            {
            case (int)NativeMethods.WindowMessages.WM_LBUTTONDOWN:
            case (int)NativeMethods.WindowMessages.WM_LBUTTONDBLCLK:
            {
                // Invoke the command object on left click
                if (Command != null && Command.CanExecute(CommandParameter))
                {
                    Command.Execute(CommandParameter);
                }
            }
            break;

            case (int)NativeMethods.WindowMessages.WM_RBUTTONDOWN:
            {
                // Open the context menu on right click
                var cursorPosition = new NativeMethods.Win32Point();
                NativeMethods.GetCursorPos(ref cursorPosition);

                using (var hWndSource = new HwndSource(new HwndSourceParameters()))
                {
                    // Adjust for non-standard DPI settings
                    var scaleFactor = new Point(hWndSource?.CompositionTarget?.TransformToDevice.M11 ?? 1,
                                                hWndSource?.CompositionTarget?.TransformToDevice.M22 ?? 1);
                    cursorPosition = new NativeMethods.Win32Point
                    {
                        X = (int)(cursorPosition.X / scaleFactor.X), Y = (int)(cursorPosition.Y / scaleFactor.Y)
                    };
                }

                if (ContextMenu != null && MessageSink != null)
                {
                    ContextMenu.DataContext      = DataContext;
                    ContextMenu.Placement        = PlacementMode.AbsolutePoint;
                    ContextMenu.HorizontalOffset = cursorPosition.X;
                    ContextMenu.VerticalOffset   = cursorPosition.Y;
                    ContextMenu.IsOpen           = true;

                    var handle = (PresentationSource.FromVisual(ContextMenu) as HwndSource)?.Handle ??
                                 MessageSink.WindowHandle;

                    NativeMethods.SetForegroundWindow(handle);
                }
            }
            break;
            }
        }
            // retrieve a point which will invoke the
            // headeritem
            private bool GetInvokationPoint(out NativeMethods.Win32Point pt)
            {
                if (!GetClickablePoint(out pt, false))
                {
                    //If there is no clickable point, there is no use of calling MapWindowPoints
                    return(false);
                }

                // Map to client
                return(Misc.MapWindowPoints(IntPtr.Zero, _hwnd, ref pt, 1));
            }
Ejemplo n.º 12
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // send an EM_CHARPOS message with an (x,y) coordinate in lParam and
        // report the returned character index and line number.
        // IMPORTANT: the character index and line number are each 16-bit (half of the lResult).
        // the high-order word is zero.
        internal void CharFromPos(NativeMethods.Win32Point point, out ushort indexLowWord, out ushort lineLowWord)
        {
            Debug.Assert(point.x >= 0 && point.x < 65536, "WindowsEditBox.CharFromPos() x coordinate out of range.");
            Debug.Assert(point.y >= 0 && point.y < 65536, "WindowsEditBox.CharFromPos() y coordinate out of range.");

            // ask edit control for line number and character offset at client coordinates.
            // low order word of return value is the character position.
            // high order word is the zero-based line index.
            IntPtr lParam = NativeMethods.Util.MAKELPARAM(point.x, point.y);
            int    result = Misc.ProxySendMessageInt(WindowHandle, NativeMethods.EM_CHARFROMPOS, IntPtr.Zero, lParam);

            indexLowWord = unchecked ((ushort)(NativeMethods.Util.LOWORD(result)));
            lineLowWord  = unchecked ((ushort)(NativeMethods.Util.HIWORD(result)));
        }
Ejemplo n.º 13
0
 private void Toggle()
 {
     // Convoluted way fake a mouse action
     NativeMethods.Win32Point pt = new NativeMethods.Win32Point();
     if (GetClickablePoint(out pt, false))
     {
         // Mouse method is used here because following methods fail:
         //     -BM_CLICK message doesn't work with all buttons (e.g. Start)
         //     -WM_MOUSEACTIVATE + WM_LBUTTONDOWN + WM_LBUTTONUP messages don't work with all buttons
         //     -WM_KEYDOWN + WM_KEYUP messages for space bar
         //     -SendKeyboardInput for space bar
         // See prior versions of this file for alternative code.
         //
         Misc.MouseClick(pt.x, pt.y);
     }
 }
Ejemplo n.º 14
0
        // Returns a Proxy element corresponding to the specified screen coordinates.
        internal override ProxySimple ElementProviderFromPoint(int x, int y)
        {
            NativeMethods.Win32Point             pt      = new NativeMethods.Win32Point(x, y);
            NativeMethods.LVHITTESTINFO_INTERNAL hitTest = WindowsListView.SubitemHitTest(_hwnd, pt);

            if ((hitTest.flags & NativeMethods.LVHT_EX_GROUP_HEADER) != 0)
            {
                return(this);
            }

            if ((hitTest.flags & NativeMethods.LVHT_ONITEM) != 0 && hitTest.iItem >= 0)
            {
                // create the item
                return(new ListViewItem(_hwnd, this, hitTest.iItem));
            }

            // If we did not land on an item we may be at a subset link these only exist
            // in v6 comctrl and vista or later.
            if (_isComctrlV6OnOsVerV6orHigher)
            {
                // Allocate a local LVHITTESTINFO struct.
                NativeMethods.LVHITTESTINFO_V6 hitTestNative = new NativeMethods.LVHITTESTINFO_V6(hitTest);
                unsafe
                {
                    XSendMessage.XSendGetIndex(_hwnd, NativeMethods.LVM_HITTEST, new IntPtr(-1), new IntPtr(&hitTestNative), Marshal.SizeOf(hitTestNative.GetType()));
                }

                if ((hitTestNative.flags & NativeMethods.LVHT_EX_GROUP_SUBSETLINK) != 0)
                {
                    GroupManager.GroupInfo groupInfo = GetGroupInfo(_hwnd, ID);
                    int [] items = groupInfo._items;
                    if (groupInfo._count <= 0 || groupInfo._count > items.Length)
                    {
                        return(null);
                    }

                    int index = items [groupInfo._count - 1];
                    return(CreateGroupSubsetLink(index + 1));
                }
            }

            return(this);
        }
Ejemplo n.º 15
0
        private void Toggle()
        {
            // Make sure that the control is enabled
            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
            {
                throw new ElementNotEnabledException();
            }

            Misc.SetFocus(_hwnd);

            NativeMethods.Win32Rect  rc = ListViewCheckBoxRect(_hwnd, _listviewItem);
            NativeMethods.Win32Point pt = new NativeMethods.Win32Point((rc.left + rc.right) / 2, (rc.top + rc.bottom) / 2);

            if (Misc.MapWindowPoints(IntPtr.Zero, _hwnd, ref pt, 1))
            {
                // "click" on the checkbox
                Misc.ProxySendMessage(_hwnd, NativeMethods.WM_LBUTTONDOWN, (IntPtr)NativeMethods.MK_LBUTTON, NativeMethods.Util.MAKELPARAM(pt.x, pt.y));
                Misc.ProxySendMessage(_hwnd, NativeMethods.WM_LBUTTONUP, IntPtr.Zero, NativeMethods.Util.MAKELPARAM(pt.x, pt.y));
            }
        }
Ejemplo n.º 16
0
        // Adds this element to the selection
        void ISelectionItemProvider.AddToSelection()
        {
            // Make sure that the control is enabled
            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
            {
                throw new ElementNotEnabledException();
            }

            // If not selectable, can't add to selection
            if (!IsSelectable())
            {
                throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
            }

            // If already selected, done
            if (((ISelectionItemProvider)this).IsSelected)
            {
                return;
            }

            // If multiple selections allowed, add requested selection
            if (WindowsTab.SupportMultipleSelection(_hwnd) == true)
            {
                // Press ctrl and mouse click tab
                NativeMethods.Win32Point pt = new NativeMethods.Win32Point();
                if (GetClickablePoint(out pt, true))
                {
                    Input.SendKeyboardInput(Key.LeftCtrl, true);
                    Misc.MouseClick(pt.x, pt.y);
                    Input.SendKeyboardInput(Key.LeftCtrl, false);
                    return;
                }

                throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
            }
            // else only single selection allowed
            else
            {
                throw new InvalidOperationException(SR.Get(SRID.DoesNotSupportMultipleSelection));
            }
        }
Ejemplo n.º 17
0
        // an improvement on EM_CHARFROMPOS that handles edit controls with content greater than 65535 characters.
        internal int CharFromPosEx(NativeMethods.Win32Point point)
        {
            // get the low words of the character position and line number at the coordinate.
            ushort indexLowWord, lineLowWord;

            CharFromPos(point, out indexLowWord, out lineLowWord);

            // we handle multi-line edit controls differently than single line edit controls.
            int index;

            if (IsMultiline)
            {
                // note: an optimization would be to call GetTextLength and do the following only if the length is
                // greater than 65535.

                // to make the line number accurate in the case there are more than 65535 lines we get a 32-bit line number
                // for the first visible line then use it to figure out the high-order word of our line number.
                // this assumes that there aren't more than 65535 visible lines in the window, which is a
                // pretty safe assumption.
                int line = IntFromLowWord(lineLowWord, GetFirstVisibleLine());

                // to make the character position accurate in case there are more than 65535 characters we use our line number to
                // get the character position of the beginning of that line and use it to figure out the high-order word
                // of our character position.
                // this assumes that there aren't more than 65535 characters on the line before our target character,
                // which is a pretty safe assumption.
                index = IntFromLowWord(indexLowWord, LineIndex(line));
            }
            else
            {
                // single-line edit control

                // to make the character position accurate in case there are more than 65535 characters we get a 32-bit
                // character position from the first visible character, then use it to figure out the high-order word
                // of our character position.
                // this assumes that there aren't more than 65535 visible characters in the window,
                // which is a pretty safe assumption.
                index = IntFromLowWord(indexLowWord, GetFirstVisibleChar());
            }
            return(index);
        }
        // Obtain clickable point on the listviewitem
        // in the case when one doesnot exist return false
        private bool GetListviewitemClickablePoint(out NativeMethods.Win32Point clickPoint)
        {
            // When this method is called, lv was already scrolled vertically
            // hence item is visible veritcally
            clickPoint.x = clickPoint.y = 0;

            NativeMethods.Win32Rect itemRectangle;

            // Obtain rectangle
            if (!WindowsListView.GetItemRect(_hwnd, _item, NativeMethods.LVIR_LABEL, out itemRectangle))
            {
                return(false);
            }

            if (WindowsListView.IsDetailMode(_hwnd) && !WindowsListView.FullRowSelect(_hwnd))
            {
                // LVS_REPORT - possible that we may need to scroll horizontaly
                //
                NativeMethods.Win32Point pt = new NativeMethods.Win32Point(itemRectangle.left, 0);

                if (!Misc.MapWindowPoints(IntPtr.Zero, _hwnd, ref pt, 1))
                {
                    return(false);
                }

                // In client coordinates, hence negative indicates that item is to the left of lv client area
                if (pt.x < 0)
                {
                    ((IScrollItemProvider)this).ScrollIntoView();

                    if (!WindowsListView.GetItemRect(_hwnd, _item, NativeMethods.LVIR_LABEL, out itemRectangle))
                    {
                        return(false);
                    }
                }
            }

            clickPoint.x = Math.Min((itemRectangle.left + 5), (itemRectangle.left + itemRectangle.right) / 2);
            clickPoint.y = (itemRectangle.top + itemRectangle.bottom) / 2;
            return(true);
        }
Ejemplo n.º 19
0
            //------------------------------------------------------
            //
            //  Private Methods
            //
            //------------------------------------------------------

            #region Private Methods

            private NativeMethods.Win32Rect GetBoundingRect()
            {
                int columns = this._altTab._altTabInfo.cColumns;
                int cxItem  = this._altTab._altTabInfo.cxItem;
                int cyItem  = this._altTab._altTabInfo.cyItem;
                int row     = _item / columns;
                int column  = _item % columns;

                NativeMethods.Win32Point ptStart = this._altTab._altTabInfo.ptStart;

                int left = ptStart.x + column * cxItem;
                int top  = ptStart.y + row * cyItem;

                NativeMethods.Win32Rect itemRect =
                    new NativeMethods.Win32Rect(left, top, left + cxItem, top + cyItem);

                if (!Misc.MapWindowPoints(_hwnd, IntPtr.Zero, ref itemRect, 2))
                {
                    // MapWindowPoints() failed.
                    itemRect = NativeMethods.Win32Rect.Empty;
                }
                return(itemRect);
            }
Ejemplo n.º 20
0
        // Press a tab
        private void Select()
        {
            if (Misc.IsBitSet(WindowStyle, (NativeMethods.TCS_BUTTONS | NativeMethods.TCS_FOCUSNEVER)))
            {
                // The TCM_SETCURFOCUS message cannot be used with TCS_FOCUSNEVER
                // use a convulated way faking a mouse action

                NativeMethods.Win32Point pt = new NativeMethods.Win32Point();
                if (GetClickablePoint(out pt, true))
                {
                    // Convert screen coordinates to client coordinates.
                    if (Misc.MapWindowPoints(IntPtr.Zero, _hwnd, ref pt, 1))
                    {
                        Misc.PostMessage(_hwnd, NativeMethods.WM_LBUTTONDOWN, (IntPtr)NativeMethods.MK_LBUTTON, NativeMethods.Util.MAKELPARAM(pt.x, pt.y));
                        Misc.PostMessage(_hwnd, NativeMethods.WM_LBUTTONUP, (IntPtr)NativeMethods.MK_LBUTTON, NativeMethods.Util.MAKELPARAM(pt.x, pt.y));
                    }
                }
            }
            else
            {
                Misc.ProxySendMessage(_hwnd, NativeMethods.TCM_SETCURFOCUS, new IntPtr(_item), IntPtr.Zero);
            }
        }
Ejemplo n.º 21
0
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // Returns the clickable point on the element
        // In the case when clickable point is obtained - method returns true
        // In the case when clickable point cannot be obtained - method returns false
        internal bool GetClickablePoint(out NativeMethods.Win32Point pt, bool fClipClientRect)
        {
            NativeMethods.Win32Rect rcItem = new NativeMethods.Win32Rect(BoundingRectangle);

            // Intersect the bounding Rectangle with the client rectangle for framents
            // and simple items - use the override flag (used mostly for the non client area
            if (fClipClientRect && !_fNonClientAreaElement)
            {
                NativeMethods.Win32Rect rcOutside = new NativeMethods.Win32Rect();

                Misc.GetClientRectInScreenCoordinates(_hwnd, ref rcOutside);

                if (!Misc.IntersectRect(ref rcItem, ref rcOutside, ref rcItem))
                {
                    pt.x = pt.y = 0;
                    return(false);
                }
            }

            ArrayList alIn  = new ArrayList(100);
            ArrayList alOut = new ArrayList(100);

            // Get the mid point to start with
            pt.x = (rcItem.right - 1 + rcItem.left) / 2;
            pt.y = (rcItem.bottom - 1 + rcItem.top) / 2;
            alOut.Add(new ClickablePoint.CPRect(ref rcItem, true));

            // First go through all the children to exclude whatever is on top
            ProxyFragment proxyFrag = this as ProxyFragment;

            if (proxyFrag != null)
            {
                ClickablePoint.ExcludeChildren(proxyFrag, alIn, alOut);
            }

            return(ClickablePoint.GetPoint(_hwnd, alIn, alOut, ref pt));
        }
Ejemplo n.º 22
0
        // Removes this element from the selection
        void ISelectionItemProvider.RemoveFromSelection()
        {
            // Make sure that the control is enabled
            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))
            {
                throw new ElementNotEnabledException();
            }

            // If not selected, done
            if (!((ISelectionItemProvider)this).IsSelected)
            {
                return;
            }

            // If multiple selections allowed, unselect element
            if (WindowsTab.SupportMultipleSelection(_hwnd) == true)
            {
                NativeMethods.Win32Point pt = new NativeMethods.Win32Point();
                if (GetClickablePoint(out pt, true))
                {
                    Input.SendKeyboardInput(Key.LeftCtrl, true);
                    Misc.MouseClick(pt.x, pt.y);
                    Input.SendKeyboardInput(Key.LeftCtrl, false);
                    return;
                }

                throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
            }
            // else if button style and single select, send deselectall message
            else if (Misc.IsBitSet(WindowStyle, NativeMethods.TCS_BUTTONS))
            {
                Misc.ProxySendMessage(_hwnd, NativeMethods.TCM_DESELECTALL, IntPtr.Zero, IntPtr.Zero);
                return;
            }

            throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
        }
Ejemplo n.º 23
0
 internal static extern bool GetPhysicalCursorPos([In, Out] ref NativeMethods.Win32Point pt);
Ejemplo n.º 24
0
        // For Vista getting the part of the titlebar that a tooltip belongs to is more
        // reliable across themes
        private string GetTitleBarToolTipTextForDWMEnabled()
        {
            // The mouse is over the titlebar item so get that point on the screen
            NativeMethods.Win32Point pt = new NativeMethods.Win32Point();
            if (!Misc.GetCursorPos(ref pt))
            {
                return("");
            }

            // Find the titlebar hwnd
            IntPtr hwnd = UnsafeNativeMethods.WindowFromPhysicalPoint(pt.x, pt.y);

            if (hwnd == IntPtr.Zero)
            {
                return("");
            }

            // Get the rects for each titlbar part
            Rect[] rects = Misc.GetTitlebarRects(hwnd);

            // Look from back to front - front is entire titlebar rect
            int scan;

            for (scan = rects.Length - 1; scan >= 0; scan--)
            {
                // Not using Misc.PtInRect because including the bounding pixels all the way around gives
                // better results; tooltips may appear when the mouse is one or two pixels outside of the
                // bounding rect so even this technique may miss.
                if (pt.x >= rects[scan].Left && pt.x <= rects[scan].Right && pt.y >= rects[scan].Top && pt.y <= rects[scan].Bottom)
                {
                    break;
                }
            }

            switch (scan)
            {
            case NativeMethods.INDEX_TITLEBAR_MINBUTTON:
                if (Misc.IsBitSet(WindowStyle, NativeMethods.WS_MINIMIZE))
                {
                    return(ST.Get(STID.LocalizedNameWindowsTitleBarButtonRestore));
                }
                else
                {
                    return(ST.Get(STID.LocalizedNameWindowsTitleBarButtonMinimize));
                }

            case NativeMethods.INDEX_TITLEBAR_HELPBUTTON:
                return(ST.Get(STID.LocalizedNameWindowsTitleBarButtonContextHelp));

            case NativeMethods.INDEX_TITLEBAR_MAXBUTTON:
                if (Misc.IsBitSet(WindowStyle, NativeMethods.WS_MAXIMIZE))
                {
                    return(ST.Get(STID.LocalizedNameWindowsTitleBarButtonRestore));
                }
                else
                {
                    return(ST.Get(STID.LocalizedNameWindowsTitleBarButtonMaximize));
                }

            case NativeMethods.INDEX_TITLEBAR_CLOSEBUTTON:
                return(ST.Get(STID.LocalizedNameWindowsTitleBarButtonClose));

            case NativeMethods.INDEX_TITLEBAR_SELF:
                return(Misc.ProxyGetText(hwnd));

            default:
                return("");
            }
        }
Ejemplo n.º 25
0
        private string GetTitleBarToolTipTextHitTest()
        {
            NativeMethods.Win32Point pt = new NativeMethods.Win32Point();
            if (!Misc.GetCursorPos(ref pt))
            {
                return("");
            }

            IntPtr hwnd = UnsafeNativeMethods.WindowFromPhysicalPoint(pt.x, pt.y);

            if (hwnd == IntPtr.Zero)
            {
                return("");
            }

            int hit = Misc.ProxySendMessageInt(hwnd, NativeMethods.WM_NCHITTEST, IntPtr.Zero, NativeMethods.Util.MAKELPARAM(pt.x, pt.y));

            switch (hit)
            {
            case NativeMethods.HTMINBUTTON:
                if (Misc.IsBitSet(Misc.GetWindowStyle(hwnd), NativeMethods.WS_MINIMIZE))
                {
                    return(ST.Get(STID.LocalizedNameWindowsTitleBarButtonRestore));
                }
                else
                {
                    return(ST.Get(STID.LocalizedNameWindowsTitleBarButtonMinimize));
                }

            case NativeMethods.HTMAXBUTTON:
                if (Misc.IsBitSet(Misc.GetWindowStyle(hwnd), NativeMethods.WS_MAXIMIZE))
                {
                    return(ST.Get(STID.LocalizedNameWindowsTitleBarButtonRestore));
                }
                else
                {
                    return(ST.Get(STID.LocalizedNameWindowsTitleBarButtonMaximize));
                }

            case NativeMethods.HTCLOSE:
            case NativeMethods.HTMDICLOSE:
                return(ST.Get(STID.LocalizedNameWindowsTitleBarButtonClose));

            case NativeMethods.HTHELP:
                return(ST.Get(STID.LocalizedNameWindowsTitleBarButtonContextHelp));

            case NativeMethods.HTMDIMINBUTTON:
                return(ST.Get(STID.LocalizedNameWindowsTitleBarButtonMinimize));

            case NativeMethods.HTMDIMAXBUTTON:
                return(ST.Get(STID.LocalizedNameWindowsTitleBarButtonMaximize));

            case NativeMethods.HTCAPTION:
                return(Misc.ProxyGetText(hwnd));

            default:
                break;
            }

            return("");
        }
Ejemplo n.º 26
0
 public static Point CorrectGetPosition(Visual relativeTo)
 {
     var w32Mouse = new NativeMethods.Win32Point();
     NativeMethods.GetCursorPos(ref w32Mouse);
     return relativeTo.PointFromScreen(new Point(w32Mouse.X, w32Mouse.Y));
 }
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        /// <summary>
        /// Return a clickable point in a Rectangle for a given window
        ///
        /// The algorithm uses the Windows Z order.
        /// To be visible, a rectangle must be enclosed in the hwnd of its parents
        /// and must but at least partially on top of the all of siblings as predecessors.
        /// In the windows ordered scheme, the first sibling comes on top followed by the
        /// next, etc. For a given hwnd, it is sufficent then to look for all the
        /// predecessor siblings.
        ///
        /// The scheme below is using recursion. This is make slightly harder to read
        /// But makes it a bit more efficent.
        /// </summary>
        /// <param name="hwnd">Window Handle</param>
        /// <param name="alIn">Input list of Rectangles to check GetPoint against</param>
        /// <param name="alOut">Output list of Rectangles after the exclusion test</param>
        /// <param name="pt">Clickable Point</param>
        /// <returns>True if there is a clickable in ro</returns>
        static internal bool GetPoint(IntPtr hwnd, ArrayList alIn, ArrayList alOut, ref NativeMethods.Win32Point pt)
        {
            IntPtr hwndStart   = hwnd;
            IntPtr hwndCurrent = hwnd;

            // Do the window on top exclusion
            // Only one level deep is necessary as grand children are clipped to their parent (our children)
            for (hwnd = Misc.GetWindow(hwnd, NativeMethods.GW_CHILD); hwnd != IntPtr.Zero; hwnd = Misc.GetWindow(hwnd, NativeMethods.GW_HWNDNEXT))
            {
                // For siblings, the element bounding rectangle must not be covered by the
                // bounding rect of its siblings
                if (!ClickableInRect(hwnd, ref pt, true, alIn, alOut))
                {
                    return(false);
                }
            }

            // Check for Parent and Sibling
            hwnd = hwndStart;
            while (true)
            {
                hwnd = Misc.GetWindow(hwnd, NativeMethods.GW_HWNDPREV);
                if (hwnd == IntPtr.Zero)
                {
                    // Very top of the Windows hierarchy we're done
                    if (hwndCurrent == _hwndDesktop)
                    {
                        break;
                    }

                    // The desktop is the parent we should stop here
                    if (Misc.IsBitSet(Misc.GetWindowStyle(hwndCurrent), NativeMethods.WS_POPUP))
                    {
                        hwnd = _hwndDesktop;
                    }
                    else
                    {
                        // We finished with all the hwnd siblings so get to the parent
                        hwnd = Misc.GetParent(hwndCurrent);
                    }

                    if (hwnd == IntPtr.Zero)
                    {
                        // final clipping against the desktop
                        hwnd = _hwndDesktop;
                    }

                    // For parent, the element bounding rectangle must be within it's parent bounding rect
                    // The desktop contains the bounding rectangle only for the main monintor, the
                    // The Progman window contains the area for the union of all the monitors
                    // Substitute the Desktop with the Progman hwnd for clipping calculation
                    IntPtr hwndClip = hwnd == _hwndDesktop ? _hwndProgman : hwnd;

                    if (!ClickableInRect(hwndClip, ref pt, false, alIn, alOut))
                    {
                        return(false);
                    }

                    // Current Parent
                    hwndCurrent = hwnd;
                    continue;
                }

                // For siblings, the element bounding rectangle must not be covered by the
                // bounding rect of its siblings
                if (!ClickableInRect(hwnd, ref pt, true, alIn, alOut))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 28
0
 private static Point GetMousePosition()
 {
     NativeMethods.Win32Point w32Mouse = new NativeMethods.Win32Point();
     NativeMethods.GetCursorPos(ref w32Mouse);
     return(new Point(w32Mouse.X, w32Mouse.Y));
 }
Ejemplo n.º 29
0
        internal void GetVisibleRangePoints(out int start, out int end)
        {
            start = 0;
            end   = 0;

            NativeMethods.Win32Rect rect = new NativeMethods.Win32Rect();

            if (Misc.GetClientRect(_hwnd, ref rect) && !rect.IsEmpty)
            {
                NativeMethods.SIZE size;
                string             s = new string('E', 1);
                GetTextExtentPoint32(s, out size);

                NativeMethods.Win32Point ptStart = new NativeMethods.Win32Point((int)(rect.left + size.cx / 4), (int)(rect.top + size.cy / 4));
                NativeMethods.Win32Point ptEnd   = new NativeMethods.Win32Point((int)(rect.right - size.cx / 8), (int)(rect.bottom - size.cy / 4));

                start = CharFromPosEx(ptStart);
                end   = CharFromPosEx(ptEnd);

                if (start > 0)
                {
                    Point pt = PosFromChar(start);
                    if (pt.X < rect.left)
                    {
                        start++;
                    }
                }
            }
            else
            {
                // multi-line edit controls are handled differently than single-line edit controls.

                if (IsMultiline)
                {
                    // get the line number of the first visible line and start the range at
                    // the beginning of that line.
                    int firstLine = GetFirstVisibleLine();
                    start = LineIndex(firstLine);

                    // calculate the line number of the first line scrolled off the bottom and
                    // end the range at the beginning of that line.
                    end = LineIndex(firstLine + LinesPerPage());
                }
                else
                {
                    // single-line edit control

                    // the problem is that using a variable-width font the number of characters visible
                    // depends on the text that is in the edit control.  so we can't just divide the
                    // width of the edit control by the width of a character.

                    // so instead we do a binary search of the characters from the first visible character
                    // to the end of the text to find the visibility boundary.
                    Rect r     = GetRect();
                    int  limit = GetTextLength();
                    start = GetFirstVisibleChar();

                    int lo = start; // known visible
                    int hi = limit; // known non-visible
                    while (lo + 1 < hi)
                    {
                        int mid = (lo + hi) / 2;

                        Point pt = PosFromChar(mid);
                        if (pt.X >= r.Left && pt.X < r.Right)
                        {
                            lo = mid;
                        }
                        else
                        {
                            hi = mid;
                        }
                    }

                    // trim off one character unless the range is empty or reaches the end.
                    end = hi > start && hi < limit ? hi - 1 : hi;
                }
            }
        }
Ejemplo n.º 30
0
 public static Point CorrectGetPosition()
 {
     var w32Mouse = new NativeMethods.Win32Point();
     NativeMethods.GetCursorPos(ref w32Mouse);
     return new Point(w32Mouse.X, w32Mouse.Y);
 }
Ejemplo n.º 31
0
 public static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, [In, Out] ref NativeMethods.Win32Point pt, int cPoints);
 private void Click(NativeMethods.Win32Point clickPoint)
 {
     Misc.MouseClick(clickPoint.x, clickPoint.y, !WindowsListView.ListViewSingleClickActivate(_hwnd));
 }