Exemple #1
0
        private static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
        {
            SafeNativeMethods.MINMAXINFO mmi   = (SafeNativeMethods.MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(SafeNativeMethods.MINMAXINFO));
            const int MONITOR_DEFAULTTONEAREST = 0x00000002;
            IntPtr    monitor = SafeNativeMethods.MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);

            if (monitor != IntPtr.Zero)
            {
                SafeNativeMethods.MONITORINFO monitorInfo   = SafeNativeMethods.GetMonitorInfoW(monitor);
                SafeNativeMethods.RECT        rcWorkArea    = monitorInfo.rcWork;
                SafeNativeMethods.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);
                mmi.ptMaxTrackSize.X = mmi.ptMaxSize.X;
                mmi.ptMaxTrackSize.Y = mmi.ptMaxSize.Y;
            }
            Marshal.StructureToPtr(mmi, lParam, true);
        }
Exemple #2
0
        private static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
        {
            SafeNativeMethods.MINMAXINFO mmi = (SafeNativeMethods.MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(SafeNativeMethods.MINMAXINFO));

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

            if (monitor != IntPtr.Zero)
            {
                SafeNativeMethods.MONITORINFO monitorInfo = new SafeNativeMethods.MONITORINFO();
                SafeNativeMethods.GetMonitorInfo(monitor, monitorInfo);
                SafeNativeMethods.RECT rcWorkArea    = monitorInfo.rcWork;
                SafeNativeMethods.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);
        }