IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { switch (msg) { case 0x0024: Win32.MINMAXINFO mmi = (Win32.MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(Win32.MINMAXINFO)); IntPtr monitor = Win32.MonitorFromWindow(hwnd, 0x00000002 /*MONITOR_DEFAULTTONEAREST*/); if (monitor != IntPtr.Zero) { Win32.MONITORINFO monitorInfo = new Win32.MONITORINFO { }; Win32.GetMonitorInfo(monitor, monitorInfo); Win32.RECT rcWorkArea = monitorInfo.rcWork; Win32.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); if (!CachedMinTrackSize.Equals(mmi.ptMinTrackSize) || CachedMinHeight != MinHeight && CachedMinWidth != MinWidth) { mmi.ptMinTrackSize.x = (int)((CachedMinWidth = MinWidth) * WindowCompositionTarget.TransformToDevice.M11); mmi.ptMinTrackSize.y = (int)((CachedMinHeight = MinHeight) * WindowCompositionTarget.TransformToDevice.M22); CachedMinTrackSize = mmi.ptMinTrackSize; } } Marshal.StructureToPtr(mmi, lParam, true); handled = true; break; } return(IntPtr.Zero); }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == Win32.WM_GETMINMAXINFO) { // Get the monitor handle. IntPtr hMonitor = Win32.MonitorFromWindow(hwnd, Win32.MONITOR_DEFAULTTONEAREST); if (hMonitor != IntPtr.Zero) { // Gets monitor information. Win32.MONITORINFO monitorInfo = Win32.MONITORINFO.Create(); if (Win32.GetMonitorInfo(hMonitor, ref monitorInfo) != 0) { // Gets the MINMAXINFO. Win32.MINMAXINFO minMaxInfo = (Win32.MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(Win32.MINMAXINFO)); if (IsFullScreenMode) { // If it is the full screen mode, it must use the entire screen. minMaxInfo.ptMaxPosition.x = monitorInfo.rcMonitor.left; minMaxInfo.ptMaxPosition.y = monitorInfo.rcMonitor.top; minMaxInfo.ptMaxSize.x = Math.Abs(monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left); minMaxInfo.ptMaxSize.y = Math.Abs(monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top); } else { // If it is not the full screen mode, it must use the work area. minMaxInfo.ptMaxPosition.x = monitorInfo.rcWork.left; minMaxInfo.ptMaxPosition.y = monitorInfo.rcWork.top; minMaxInfo.ptMaxSize.x = Math.Abs(monitorInfo.rcWork.right - monitorInfo.rcWork.left); minMaxInfo.ptMaxSize.y = Math.Abs(monitorInfo.rcWork.bottom - monitorInfo.rcWork.top); } // Sets the modified MINMAXINFO. Marshal.StructureToPtr(minMaxInfo, lParam, false); handled = true; } } // if (hMonitor != IntPtr.Zero) } // if (msg == Win32.WM_GETMINMAXINFO) return(IntPtr.Zero); }