我正在开发一个WPF应用程序,并在窗口周围添加了一个清晰的边框,以便可以从主窗口外调整大小。我已经重写了MINMAXINFO,如此处所示。使用下面的代码,当我进行常规最大化时,您看不到无形的边框。但是,当我尝试垂直最大化(通过将窗口顶部拖到屏幕顶部)时,会显示无形的边框。我已经尝试捕获所有消息,但我找不到垂直最大化的单独消息。如何在这种情况下移除无形的边框?
private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam) {
MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
// Adjust the maximized size and position to fit the work area of the correct monitor
int MONITOR_DEFAULTTONEAREST = 0x00000002;
System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (monitor != System.IntPtr.Zero) {
MONITORINFO monitorInfo = new MONITORINFO();
GetMonitorInfo(monitor, monitorInfo);
RECT rcWorkArea = monitorInfo.rcWork;
RECT rcMonitorArea = monitorInfo.rcMonitor;
mmi.ptMaxPosition.x = Math.Abs (rcWorkArea.left - rcMonitorArea.left) - borderThickness;
mmi.ptMaxPosition.y = Math.Abs (rcWorkArea.top - rcMonitorArea.top) - borderThickness;
mmi.ptMaxSize.x = Math.Abs (rcWorkArea.right - rcWorkArea.left) + 2 * borderThickness;
mmi.ptMaxSize.y = Math.Abs (rcWorkArea.bottom - rcWorkArea.top) + 2 * borderThickness;
}
Marshal.StructureToPtr(mmi, lParam, true);
}