There is a note down in the documentation for the MINMAXINFO
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_GETMINMAXINFO
message to a top-level window, the MINMAXINFO
structure comes preinitialized with the following information:
Member | Initialized To |
---|---|
ptMaxSize | The dimensions of the primary monitor. |
ptMaxPosition | The upper left corner of the window if it were maximized on the primary monitor. |
ptMinTrackSize | The minimum size the user can resize the window. |
ptMaxTrackSize | The 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.
ptMaxPosition is easy. The point is moved to a corresponding relative position on the window’s actual monitor.
ptMaxSize is trickier. If the specified size is greater than or equal to the size of the primary monitor, then the ptMaxSize is adjusted to include the difference in size between the primary monitor and the actual monitor. In other words, if ptMaxSize is 20 pixels larger than the primary monitor, then it will be adjusted to being 20 pixels larger than the actual monitor. But if ptMaxSize 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 MonitorFromWindow
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.
0 comments