Пример #1
0
        internal static void FindMaximumSingleMonitorRectangle(RECT windowRect, out RECT screenSubRect, out RECT monitorRect)
        {
            int displayForWindowRect = FindDisplayForWindowRect(new Rect(windowRect.Left, windowRect.Top, windowRect.Width, windowRect.Height));

            screenSubRect = new RECT
            {
                Left   = 0,
                Right  = 0,
                Top    = 0,
                Bottom = 0
            };
            monitorRect = new RECT
            {
                Left   = 0,
                Right  = 0,
                Top    = 0,
                Bottom = 0
            };
            if (-1 == displayForWindowRect)
            {
                return;
            }
            Monitorinfo display = Displays[displayForWindowRect];
            RECT        rcWork  = display.RcWork;
            RECT        lprcDst;

            User32.IntersectRect(out lprcDst, ref rcWork, ref windowRect);
            screenSubRect = lprcDst;
            monitorRect   = display.RcWork;
        }
Пример #2
0
        public static Rect AbsoluteRectToRelativeRect(int display, Rect absoluteRect)
        {
            Validate.IsWithinRange(display, 0, Displays.Count - 1, "display");
            RECT rcMonitor = Displays[display].RcMonitor;

            return(new Rect(absoluteRect.X - rcMonitor.Left, absoluteRect.Y - rcMonitor.Top, absoluteRect.Width, absoluteRect.Height));
        }
Пример #3
0
        public static int FindDisplayForWindowRect(Rect windowRect)
        {
            int  num1     = -1;
            RECT lprcSrc2 = new RECT(windowRect);
            long num2     = 0;

            for (int index = 0; index < Displays.Count; ++index)
            {
                RECT rcWork = Displays[index].RcWork;
                RECT lprcDst;
                User32.IntersectRect(out lprcDst, ref rcWork, ref lprcSrc2);
                long num3 = lprcDst.Width * lprcDst.Height;
                if (num3 > num2)
                {
                    num1 = index;
                    num2 = num3;
                }
            }
            if (-1 == num1)
            {
                double num3 = double.MaxValue;
                for (int index = 0; index < Displays.Count; ++index)
                {
                    double num4 = Distance(Displays[index].RcMonitor, lprcSrc2);
                    if (num4 < num3)
                    {
                        num1 = index;
                        num3 = num4;
                    }
                }
            }
            return(num1);
        }
Пример #4
0
        public static Point RelativePositionToAbsolutePosition(int display, double left, double top)
        {
            if (display < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(display));
            }
            RECT rect;

            if (display >= Displays.Count)
            {
                Monitorinfo display1 = Displays[Displays.Count - 1];
                rect = new RECT(display1.RcMonitor.Left + display1.RcMonitor.Width, display1.RcMonitor.Top, display1.RcMonitor.Right + display1.RcMonitor.Width, display1.RcMonitor.Bottom);
            }
            else
            {
                rect = Displays[display].RcMonitor;
            }
            return(new Point(rect.Left + left, rect.Top + top));
        }
Пример #5
0
        public static int FindDisplayForAbsolutePosition(Point absolutePosition)
        {
            for (int index = 0; index < Displays.Count; ++index)
            {
                RECT rcMonitor = Displays[index].RcMonitor;
                if (rcMonitor.Left <= absolutePosition.X && rcMonitor.Right >= absolutePosition.X && (rcMonitor.Top <= absolutePosition.Y && rcMonitor.Bottom >= absolutePosition.Y))
                {
                    return(index);
                }
            }
            int    num1 = -1;
            double num2 = double.MaxValue;

            for (int index = 0; index < Displays.Count; ++index)
            {
                double num3 = Distance(absolutePosition, Displays[index].RcMonitor);
                if (num3 < num2)
                {
                    num1 = index;
                    num2 = num3;
                }
            }
            return(num1);
        }
Пример #6
0
 internal static extern IntPtr CreateRectRgnIndirect(ref RECT lprc);
Пример #7
0
 internal static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
Пример #8
0
 internal static extern bool GetClientRect(IntPtr hwnd, out RECT lpRect);
Пример #9
0
 internal static extern bool FillRect(IntPtr hDc, ref RECT rect, IntPtr hbrush);
Пример #10
0
 public static extern IntPtr MonitorFromRect([In] ref RECT lprc, uint dwFlags);
Пример #11
0
 internal static extern bool IntersectRect(out RECT lprcDst, [In] ref RECT lprcSrc1, [In] ref RECT lprcSrc2);
Пример #12
0
 private static Point GetRectCenter(RECT rect)
 {
     return(new Point(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2));
 }
Пример #13
0
 private static double Distance(Point point, RECT rect)
 {
     return(Distance(point, GetRectCenter(rect)));
 }
Пример #14
0
 private static double Distance(RECT rect1, RECT rect2)
 {
     return(Distance(GetRectCenter(rect1), GetRectCenter(rect2)));
 }