Esempio n. 1
0
 private static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO lpmi);
Esempio n. 2
0
        public static void GetMinMaxInfo(Window window, IntPtr hwnd, IntPtr lParam)
        {
            var mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
            var hMonitor = MonitorFromWindow(hwnd, 0x02);
            if (hMonitor != IntPtr.Zero)
            {
                var mi = new MONITORINFO();
                mi.cbSize = Marshal.SizeOf(typeof(MONITORINFO));
                GetMonitorInfo(hMonitor, ref mi);
                RECT rcWorkArea = mi.rcWork;
                RECT rcMonitorArea = mi.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.ptMinTrackSize.X = (int)window.MinWidth;
                mmi.ptMinTrackSize.Y = (int)window.MinHeight;
            }

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