Example #1
0
        public static Point ClientToScreen(Point point, IntPtr clientHandle)
        {
            POINT p = point.ToPOINT();

            MapWindowPoints(clientHandle, IntPtr.Zero, ref p, 1);
            return(p.ToPoint());
        }
Example #2
0
        public static MouseState GetState()
        {
#if MONOMAC
            //We need to maintain precision...
            State.ScrollWheelValue = (int)ScrollWheelValue;
#elif WINDOWS || LINUX
            // maybe someone is tring to get mouse before initialize
            if (_mouse == null)
            {
                return(State);
            }

#if WINDOWS
            var p = new POINT();
            GetCursorPos(out p);
            var pc = Window.PointToClient(p.ToPoint());
            State.X = pc.X;
            State.Y = pc.Y;
#endif

            State.LeftButton   = _mouse[OpenTK.Input.MouseButton.Left] ? ButtonState.Pressed : ButtonState.Released;
            State.RightButton  = _mouse[OpenTK.Input.MouseButton.Right] ? ButtonState.Pressed : ButtonState.Released;
            State.MiddleButton = _mouse[OpenTK.Input.MouseButton.Middle] ? ButtonState.Pressed : ButtonState.Released;;

            // WheelPrecise is divided by 120 (WHEEL_DELTA) in OpenTK (WinGLNative.cs)
            // We need to counteract it to get the same value XNA provides
            State.ScrollWheelValue = (int)(_mouse.WheelPrecise * 120);
#endif

            return(State);
        }
        public static Point PointToScreen([NotNull] this IWin32Window thisValue, Point p)
        {
            POINT pt = p.ToWin32Point();

            Win32.MapWindowPoints(thisValue.Handle, IntPtr.Zero, ref pt, 1);
            return(pt.ToPoint());
        }
        public static Point MapPoint(this IWin32Window thisValue, Point pt, IWin32Window newWin = null)
        {
            POINT pnt = pt.ToWin32Point();

            Win32.MapWindowPoints(thisValue?.Handle ?? IntPtr.Zero, newWin?.Handle ?? IntPtr.Zero, ref pnt, 1);
            return(pnt.ToPoint());
        }
Example #5
0
        public static Point GetCursorPos()
        {
            POINT pt = new POINT();

            WinApi.GetCursorPos(ref pt);
            return(pt.ToPoint());
        }
Example #6
0
        private object findControl(int x, int y)
        {
            //Point newPoint = this.PointToScreen(new Point(x, y));
            //POINT windowPoint = POINT.FromPoint(newPoint);
            POINT  windowPoint = new POINT(x, y);
            IntPtr found       = NativeUtils.WindowFromPoint(windowPoint);

            // we have a valid window handle
            if (found != IntPtr.Zero)
            {
                // give it another try, it might be a child window (disabled, hidden .. something else)
                // offset the point to be a client point of the active window
                if (NativeUtils.ScreenToClient(found, ref windowPoint))
                {
                    // check if there is some hidden/disabled child window at this point
                    IntPtr childWindow = NativeUtils.ChildWindowFromPoint(found, windowPoint);
                    if (childWindow != IntPtr.Zero)
                    { // great, we have the inner child
                        found = childWindow;
                    }
                }

                object c = Control.FromHandle(found);

                /*if (c is MenuStrip)//MenuStrip继承自ToolStrip
                 * {
                 *  MenuStrip m = c as MenuStrip;
                 *  c = m.GetItemAt(windowPoint.ToPoint());
                 * }
                 * else*/if (c is ToolStripDropDownMenu)
                {
                    ToolStripDropDownMenu m = c as ToolStripDropDownMenu;
                    c = m.GetItemAt(windowPoint.ToPoint());
                }
                else if (c is ToolStrip)
                {
                    ToolStrip m = c as ToolStrip;
                    c = m.GetItemAt(windowPoint.ToPoint());
                }

                return(c);
            }
            else
            {
                return(null);
            }
        }
        Point ClientToScreen(SystemWindow systemWindow, Point clientPoint)
        {
            POINT point = clientPoint.ToPOINT();

            int result = NativeMethods.MapWindowPoints(systemWindow.HWnd, IntPtr.Zero, ref point, 1);

            //if (result == 0)
            //    throw new Exception("could not get client coordinates");
            return(point.ToPoint());
        }