How does the window manager adjust ptMaxSize and ptMaxPosition for multiple monitors?

Raymond Chen


There is a note down in the documentation for the MIN­MAX­INFO structure:

For systems with multiple monitors, the ptMaxSize and ptMaxPosition members describe the maximized size and position of the window on the primary monitor, even if the window ultimately maximizes onto a secondary monitor. In that case, the window manager adjusts these values to compensate for differences between the primary monitor and the monitor that displays the window.

People ask about the nature of this “compensation” and how they should deal with it.

When the window manager sends the WM_GET­MIN­MAX­INFO message to a top-level window, the MIN­MAX­INFO structure comes preinitialized with the following information:

MemberInitialized To
ptMaxSizeThe dimensions of the primary monitor.
ptMaxPositionThe upper left corner of the window if it were maximized on the primary monitor.
ptMinTrackSizeThe minimum size the user can resize the window.
ptMaxTrackSizeThe maximum size the user can resize the window (the union of all monitors, basically).

Two of these values are monitor-relative and are therefore subject to adjustment.

ptMax­Position is easy. The point is moved to a corresponding relative position on the window’s actual monitor.

ptMax­Size is trickier. If the specified size is greater than or equal to the size of the primary monitor, then the ptMax­Size is adjusted to include the difference in size between the primary monitor and the actual monitor. In other words, if ptMax­Size is 20 pixels larger than the primary monitor, then it will be adjusted to being 20 pixels larger than the actual monitor. But if ptMax­Size does not completely cover the monitor, then its value is used as-is.

That is what the documentation is referring to when it says “In that case.” The case is “if the window ultimately maximizes onto a secondary monitor.”

There is a bit of a gotcha here: If your window is larger than the screen in one direction but not another. For example, you may have a narrow maximum width but a tall maximum height. (Think console windows.) In that case, you will need to use Monitor­From­Window to get the parameters for the actual monitor so you can set your maximum height appropriately.

We’ll dig a little deeper into this gotcha next time.


Comments are closed. Login to edit/delete your existing comments