How to account for frame size when handling WM_GETMINMAXINFO

1.4k Views Asked by At

I have a WPF app that handles WM_GETMINMAXINFO in order to customize the Window chrome and still honor the system taskbar. That is, when you maximize the window on the monitor with the taskbar on it, it will not cover the taskbar. This works fine, except the window's frame is still visible when maximized, which is both ugly and useless because the window can't be resized when it's maximized anyway.

To combat this, I figured I need to alter my handling of WM_GETMINMAXINFO to increase the size of the window like this:

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;

This actually works, but my concern is the last four lines where I assume that the frame width is 2 pixels. Is there a more generic approach to obtaining the frame width so I can accommodate it in my WM_GETMINMAXINFO handler?

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

Sertac got me off on the right direction by pointing out the GetSystemMetrics Win32 API. This reminded me of WPF's SystemParameters class, in which I found the FixedFrameHorizontalBorderHeight and FixedFrameVerticalBorderWidth properties. These are exactly what I needed:

// 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);