我有一个处理 WM_GETMINMAXINFO 的 WPF 应用程序,以便自定义窗口镶边并仍然尊重系统任务栏。也就是说,当您最大化带有任务栏的显示器上的窗口时,它不会覆盖任务栏。这工作得很好,只是窗口的框架在最大化时仍然可见,这既丑陋又无用,因为窗口在最大化时无论如何都无法调整大小。
为了解决这个问题,我认为我需要改变对 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
处理程序中?
谢谢
最佳答案
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);
关于wpf - 处理 WM_GETMINMAXINFO 时如何考虑帧大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5351543/