我有一个处理WM_GETMINMAXINFO的WPF应用程序,以便自定义Window chrome并仍然尊重系统任务栏。也就是说,当您使用任务栏对显示器上的窗口进行最大化时,它将不会覆盖任务栏。这样可以正常工作,除非窗口的框架在最大化时仍然可见,这既丑又无用,因为无论如何窗口都无法调整大小。
为了解决这个问题,我想我需要改变对WM_GETMINMAXINFO
的处理,以增加窗口的大小:
var monitorInfo = new SafeNativeMethods.MONITORINFO
{
cbSize = Marshal.SizeOf(typeof(SafeNativeMethods.MONITORINFO))
};
SafeNativeMethods.GetMonitorInfo(monitor, ref monitorInfo);
var workArea = monitorInfo.rcWork;
var monitorArea = monitorInfo.rcMonitor;
minMaxInfo.ptMaxPosition.x = Math.Abs(workArea.left - monitorArea.left);
minMaxInfo.ptMaxPosition.y = Math.Abs(workArea.top - monitorArea.top);
minMaxInfo.ptMaxSize.x = Math.Abs(workArea.right - workArea.left);
minMaxInfo.ptMaxSize.y = Math.Abs(workArea.bottom - workArea.top);
// increase size to account for frame
minMaxInfo.ptMaxPosition.x -= 2;
minMaxInfo.ptMaxPosition.y -= 2;
minMaxInfo.ptMaxSize.x += 4;
minMaxInfo.ptMaxSize.y += 4;
这实际上有效,但我关注的是最后四行,我假设帧宽为2像素。是否有更通用的方法来获取帧宽度,以便我可以在WM_GETMINMAXINFO
处理程序中容纳它?
由于
答案 0 :(得分:3)
Sertac通过指出GetSystemMetrics
Win32 API让我走上正确的方向。这让我想起了WPF的SystemParameters
课程,其中我找到了FixedFrameHorizontalBorderHeight
和FixedFrameVerticalBorderWidth
属性。这些正是我所需要的:
// increase size to account for frame
minMaxInfo.ptMaxPosition.x -= (int)SystemParameters.FixedFrameVerticalBorderWidth;
minMaxInfo.ptMaxPosition.y -= (int)SystemParameters.FixedFrameHorizontalBorderHeight;
minMaxInfo.ptMaxSize.x += (int)(SystemParameters.FixedFrameVerticalBorderWidth * 2);
minMaxInfo.ptMaxSize.y += (int)(SystemParameters.FixedFrameHorizontalBorderHeight * 2);