Handling WM_GETMINMAXINFO for multiple monitors
<p>The <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms632605%28v=vs.85%29.aspx" rel="nofollow noreferrer">docs</a> for the <code>ptMaxSize</code> and <code>ptMaxPosition</code> components of <code>MINMAXINFO</code> say:</p>
<blockquote>
<p>For top-level windows, this value is based on (...) the primary monitor.</p>
</blockquote>
<p>Raymond Chen <a href="https://devblogs.microsoft.com/oldnewthing/20150501-00/?p=44964" rel="nofollow noreferrer">elaborates</a>:</p>
<blockquote>
<p>If the specified size is greater than or equal to the size of the primary monitor, then the <code>ptMax­Size</code> is adjusted to include the difference in size between the primary monitor and the actual monitor. (...) But if <code>ptMax­Size</code> does not completely cover the monitor, then its value is used as-is.</p>
</blockquote>
<p>So, if I want to fill out <code>MINMAXINFO</code> such that a window maximised to a nonprimary monitor, in a setup with a primary monitor of a different resolution / orientation, fills the work area, but without overlapping the taskbar if that happens to be on the same monitor... how do I reliably do that?</p>
<p>ISTM that, once I've obtained the work area dimensions for the monitor the window is on and calculated the desired window max size:</p>
<ul>
<li>if the primary monitor is the same width or wider than the work area, I can leave the width alone</li>
<li>otherwise, if the window is wider than the monitor it is on, I can subtract the difference between the monitor widths</li>
<li>otherwise, I have no means of describing the width I want</li>
</ul>
<p>...and the same for height.</p>
<p>If I code that up, I do get exactly the described behaviour... <em>except</em> in the case where the monitors have the same resolution but different orientation, where the adjustment doesn't seem to get applied.</p>
<p>This all seems incredibly convoluted and odd. Am I missing or misunderstanding something? Is there actually some simple robust calculation I should be doing instead?</p>