예제 #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
        private void WmGetMinMaxInfo(IntPtr lParam)
        {
            MaxHeight = System.Windows.Forms.Screen.FromHandle(new WindowInteropHelper(this).Handle).WorkingArea.Height;
            GetCursorPos(out var lMousePosition);

            var lPrimaryScreen     = MonitorFromPoint(new Point(0, 0), MonitorOptions.MonitorDefaulttoprimary);
            var lPrimaryScreenInfo = new Monitorinfo();

            if (GetMonitorInfo(lPrimaryScreen, lPrimaryScreenInfo) == false)
            {
                return;
            }

            var lCurrentScreen = MonitorFromPoint(lMousePosition, MonitorOptions.MonitorDefaulttonearest);
            var lMmi           = (Minmaxinfo)Marshal.PtrToStructure(lParam, typeof(Minmaxinfo));

            if (lPrimaryScreen.Equals(lCurrentScreen))
            {
                lMmi.ptMaxPosition.X = lPrimaryScreenInfo.rcWork.Left;
                lMmi.ptMaxPosition.Y = lPrimaryScreenInfo.rcWork.Top;
                lMmi.ptMaxSize.X     = lPrimaryScreenInfo.rcWork.Right - lPrimaryScreenInfo.rcWork.Left;
                lMmi.ptMaxSize.Y     = lPrimaryScreenInfo.rcWork.Bottom - lPrimaryScreenInfo.rcWork.Top;
            }
            else
            {
                lMmi.ptMaxPosition.X = lPrimaryScreenInfo.rcMonitor.Left;
                lMmi.ptMaxPosition.Y = lPrimaryScreenInfo.rcMonitor.Top;
                lMmi.ptMaxSize.X     = lPrimaryScreenInfo.rcMonitor.Right - lPrimaryScreenInfo.rcMonitor.Left;
                lMmi.ptMaxSize.Y     = lPrimaryScreenInfo.rcMonitor.Bottom - lPrimaryScreenInfo.rcMonitor.Top;
            }

            Marshal.StructureToPtr(lMmi, lParam, true);
        }
예제 #3
0
        internal static Monitorinfo MonitorInfoFromWindow(IntPtr hWnd)
        {
            var hMonitor    = User32.MonitorFromWindow(hWnd, 2);
            var monitorInfo = new Monitorinfo {
                CbSize = (uint)Marshal.SizeOf(typeof(Monitorinfo))
            };

            User32.GetMonitorInfo(hMonitor, ref monitorInfo);
            return(monitorInfo);
        }
        private static Monitorinfo MonitorInfoFromWindow(IntPtr hWnd)
        {
            var hMonitor    = NativeMethods.MonitorFromWindow(hWnd, 2);
            var monitorInfo = new Monitorinfo {
                CbSize = (uint)Marshal.SizeOf(typeof(Monitorinfo))
            };

            NativeMethods.GetMonitorInfo(hMonitor, ref monitorInfo);
            return(monitorInfo);
        }
예제 #5
0
        internal static Monitorinfo MonitorInfoFromWindow(Window window)
        {
            var interop = new WindowInteropHelper(window);

            interop.EnsureHandle();
            var handle      = interop.Handle;
            var hMonitor    = User32.MonitorFromWindow(handle, 2);
            var monitorInfo = new Monitorinfo {
                CbSize = (uint)Marshal.SizeOf(typeof(Monitorinfo))
            };

            User32.GetMonitorInfo(hMonitor, ref monitorInfo);
            return(monitorInfo);
        }
예제 #6
0
        internal static void FindMaximumSingleMonitorRectangle(RECT windowRect, out RECT screenSubRect,
                                                               out RECT monitorRect)
        {
            List <RECT> rects = new List <RECT>();

            User32.EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero,
                                       (IntPtr hMonitor, IntPtr hdcMonitor, ref RECT rect, IntPtr lpData) =>
            {
                var monitorInfo = new Monitorinfo {
                    CbSize = (uint)Marshal.SizeOf(typeof(Monitorinfo))
                };
                User32.GetMonitorInfo(hMonitor, ref monitorInfo);
                rects.Add(monitorInfo.RcWork);
                return(true);
            }, IntPtr.Zero);
            long num1 = 0;

            screenSubRect = new RECT()
            {
                Left   = 0,
                Right  = 0,
                Top    = 0,
                Bottom = 0
            };
            monitorRect = new RECT()
            {
                Left   = 0,
                Right  = 0,
                Top    = 0,
                Bottom = 0
            };
            foreach (RECT rect in rects)
            {
                RECT lprcSrc1 = rect;
                RECT lprcDst;
                User32.IntersectRect(out lprcDst, ref lprcSrc1, ref windowRect);
                long num2 = lprcDst.Width * lprcDst.Height;
                if (num2 > num1)
                {
                    screenSubRect = lprcDst;
                    monitorRect   = rect;
                    num1          = num2;
                }
            }
        }
예제 #7
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));
        }
예제 #8
0
        public static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
        {
            var mmi = (Minmaxinfo)Marshal.PtrToStructure(lParam, typeof(Minmaxinfo));
            var MONITOR_DEFAULTTONEAREST = 0x00000002;
            var monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);

            if (monitor != IntPtr.Zero)
            {
                var monitorInfo = new Monitorinfo();
                GetMonitorInfo(monitor, monitorInfo);
                var rcWorkArea    = monitorInfo.rcWork;
                var rcMonitorArea = monitorInfo.rcMonitor;
                mmi.ptMaxPosition.x  = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
                mmi.ptMaxPosition.y  = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
                mmi.ptMaxSize.x      = Math.Abs(rcWorkArea.right - rcWorkArea.left);
                mmi.ptMaxSize.y      = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
                mmi.ptMaxTrackSize.x = mmi.ptMaxSize.x;
                mmi.ptMaxTrackSize.y = mmi.ptMaxSize.y;
            }

            Marshal.StructureToPtr(mmi, lParam, true);
        }
예제 #9
0
        internal static void FindMonitorRectsFromPoint(Point point, out Rect monitorRect, out Rect workAreaRect)
        {
            IntPtr hMonitor = User32.MonitorFromPoint(new Platform.Structs.Point
            {
                X = (int)point.X,
                Y = (int)point.Y
            }, 2);

            monitorRect  = new Rect(0.0, 0.0, 0.0, 0.0);
            workAreaRect = new Rect(0.0, 0.0, 0.0, 0.0);
            if (!(hMonitor != IntPtr.Zero))
            {
                return;
            }
            var monitorInfo = new Monitorinfo {
                CbSize = (uint)Marshal.SizeOf(typeof(Monitorinfo))
            };

            User32.GetMonitorInfo(hMonitor, ref monitorInfo);
            monitorRect  = new Rect(monitorInfo.RcMonitor.Position, monitorInfo.RcMonitor.Size);
            workAreaRect = new Rect(monitorInfo.RcWork.Position, monitorInfo.RcWork.Size);
        }
예제 #10
0
        internal static void FindMonitorRectsFromPoint(System.Windows.Point point, out Rect monitorRect, out Rect workAreaRect)
        {
            var hMonitor = NativeMethods.NativeMethods.MonitorFromPoint(new Point
            {
                X = (int)point.X,
                Y = (int)point.Y
            }, 2);

            monitorRect  = new Rect(0.0, 0.0, 0.0, 0.0);
            workAreaRect = new Rect(0.0, 0.0, 0.0, 0.0);
            if (!(hMonitor != IntPtr.Zero))
            {
                return;
            }
            var monitorInfo = new Monitorinfo {
                CbSize = (uint)Marshal.SizeOf(typeof(Monitorinfo))
            };

            NativeMethods.NativeMethods.GetMonitorInfo(hMonitor, ref monitorInfo);
            monitorRect  = new Rect(monitorInfo.RcMonitor.Position, monitorInfo.RcMonitor.Size);
            workAreaRect = new Rect(monitorInfo.RcWork.Position, monitorInfo.RcWork.Size);
        }
예제 #11
0
        private static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lparam)
        {
            var mmi = (Minmaxinfo)Marshal.PtrToStructure(lparam, typeof(Minmaxinfo));

            const int monitorDefaultToNearest = 0x00000002;
            var       monitor = NativeMethods.MonitorFromWindow(hwnd, monitorDefaultToNearest);

            if (monitor != IntPtr.Zero)
            {
                var monitorInfo = new Monitorinfo();
                NativeMethods.GetMonitorInfo(monitor, monitorInfo);

                var rcWorkArea    = monitorInfo.rcWork;
                var rcMonitorArea = monitorInfo.rcMonitor;

                mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
                mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
                mmi.ptMaxSize.x     = Math.Abs(rcWorkArea.right - rcWorkArea.left);
                mmi.ptMaxSize.y     = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
            }

            Marshal.StructureToPtr(mmi, lparam, true);
        }
예제 #12
0
        private static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
        {
            var mmi = (Minmaxinfo)Marshal.PtrToStructure(lParam, typeof(Minmaxinfo));
            var monitorContainingApplication = MonitorFromWindow(hwnd, MonitorDefaulttOnNearest);

            if (monitorContainingApplication != IntPtr.Zero)
            {
                var monitorInfo = new Monitorinfo();
                GetMonitorInfo(monitorContainingApplication, monitorInfo);
                var rcWorkArea    = monitorInfo.rcWork;
                var rcMonitorArea = monitorInfo.rcMonitor;
                mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
                mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
                mmi.ptMaxSize.x     = Math.Abs(rcWorkArea.right - rcWorkArea.left);
                mmi.ptMaxSize.y     = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
                //mmi.ptMaxTrackSize.x = mmi.ptMaxSize.x;
                //mmi.ptMaxTrackSize.y = mmi.ptMaxSize.y;
                mmi.ptMinTrackSize.x = 20;
                mmi.ptMinTrackSize.y = 20;
                mmi = AdjustWorkingAreaForAutoHide(monitorContainingApplication, mmi);
            }
            Marshal.StructureToPtr(mmi, lParam, true);
        }
예제 #13
0
        private static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
        {
            var mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));

            const int monitorDefaulttonearest = 0x00000002;
            var       monitor = MonitorFromWindow(hwnd, monitorDefaulttonearest);

            if (monitor != IntPtr.Zero)
            {
                var monitorInfo = new Monitorinfo();
                GetMonitorInfo(monitor, monitorInfo);
                var rcWorkArea    = monitorInfo.rcWork;
                var rcMonitorArea = monitorInfo.rcMonitor;
                mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
                mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
                mmi.ptMaxSize.x     = Math.Abs(rcMonitorArea.right - rcWorkArea.left);
                mmi.ptMaxSize.y     = Math.Abs(rcMonitorArea.bottom - rcWorkArea.top);
                //最大化不覆盖菜单栏
                //mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
                //mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
            }

            Marshal.StructureToPtr(mmi, lParam, true);
        }
예제 #14
0
 internal static extern bool GetMonitorInfo(IntPtr hMonitor, Monitorinfo lpmi);
예제 #15
0
        private static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
        {

            Minmaxinfo mmi = (Minmaxinfo)Marshal.PtrToStructure(lParam, typeof(Minmaxinfo));

            // Adjust the maximized size and position to fit the work area of the correct monitor
            int MONITOR_DEFAULTTONEAREST = 0x00000002;
            IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);

            if (monitor != IntPtr.Zero)
            {

                Monitorinfo monitorInfo = new Monitorinfo();
                GetMonitorInfo(monitor, monitorInfo);
                Rect rcWorkArea = monitorInfo.rcWork;
                Rect rcMonitorArea = monitorInfo.rcMonitor;
                mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
                mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
                mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
                mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
            }

            Marshal.StructureToPtr(mmi, lParam, true);
        }
예제 #16
0
 internal static extern bool GetMonitorInfo(IntPtr hMonitor, Monitorinfo lpmi);
예제 #17
0
 private static extern bool GetMonitorInfo(IntPtr hMonitor, Monitorinfo lpmi);
예제 #18
0
 internal static extern bool GetMonitorInfo(IntPtr hMonitor, ref Monitorinfo monitorInfo);
예제 #19
0
파일: UIWindow.cs 프로젝트: iFaxity/FaxLib
        static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
        {
            var mmi = (Minmaxinfo)Marshal.PtrToStructure(lParam, typeof(Minmaxinfo));

            const int monitorDefaulttonearest = 0x00000002;
            var monitor = NativeMethods.MonitorFromWindow(hwnd, monitorDefaulttonearest);

            if(monitor != IntPtr.Zero) {
                var monitorInfo = new Monitorinfo();
                NativeMethods.GetMonitorInfo(monitor, monitorInfo);

                var rcWorkArea = monitorInfo.rcWork;
                var rcMonitorArea = monitorInfo.rcMonitor;

                mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
                mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
                mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
                mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
            }

            Marshal.StructureToPtr(mmi, lParam, true);
        }