I'm working on a WPF application and I've added a clear border around the window so that it can be resized from outside the main window. I've overridden MINMAXINFO as shown here. With the below code, when I do a regular maximize you can't see the invisible border. However, when I try to maximize vertically (by dragging the top of the window to the top of the screen) the invisible border is shown. I've tried catching all the messages and I couldn't find a separate message for vertical maximization. How can I remove the invisible border for this case?
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);
}