I have a wpf application and I manage max sizing with WmGetMinMaxInfo:
private static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
{
MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
IntPtr monitorContainingApplication = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (monitorContainingApplication != System.IntPtr.Zero)
{
MONITORINFO monitorInfo = new MONITORINFO();
GetMonitorInfo(monitorContainingApplication, 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);
mmi.ptMaxTrackSize.x = mmi.ptMaxSize.x;
mmi.ptMaxTrackSize.y = mmi.ptMaxSize.y;
}
Marshal.StructureToPtr(mmi, lParam, true);
}
My window are set to :
WindowStyle="None"
ResizeMode="CanResizeWithGrip"
AllowsTransparency="True"
I have an wierd issue when I minimized the app at maximized state and when click for return at the taskbar icon to come back on the maximized window app.
It don't take the full screen, It's seems to take the primary screen resolution. I got that case when I don't have the same resolution between primary and secondary screen (Obviously my secondary are bigger than the first one).
Do you have any ideas where is the issue ? Windows features ? There is any work around ?
SOLUTION: I have solved my issue with the idea of Keithernet to not recalculate when the windowState are minimized. Thank !
private static void WmGetMinMaxInfo(IntPtr hwnd, IntPtr lParam)
{
MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
IntPtr monitorContainingApplication = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (monitorContainingApplication != System.IntPtr.Zero)
{
MONITORINFO monitorInfo = new MONITORINFO();
GetMonitorInfo(monitorContainingApplication, monitorInfo);
RECT rcWorkArea = monitorInfo.rcWork;
RECT rcMonitorArea = monitorInfo.rcMonitor;
if (Application.Current.MainWindow.WindowState != WindowState.Minimized)
{
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;
lastGoodMaxTrackSize = mmi.ptMaxTrackSize;
lastGoodMaxPosition = mmi.ptMaxPosition;
lastGoodMaxSize = mmi.ptMaxSize;
}
else
{
mmi.ptMaxPosition = lastGoodMaxPosition;
mmi.ptMaxSize = lastGoodMaxSize;
mmi.ptMaxTrackSize = lastGoodMaxTrackSize;
}
mmi = AdjustWorkingAreaForAutoHide(monitorContainingApplication, mmi);
}
Marshal.StructureToPtr(mmi, lParam, true);
}