title: Calculating the correct width to resize image to display in a CListCtrl
body: <p>At the moment I am having to fudge my code like this:</p>
  <pre><code>CRect rcList;
  m_ListThumbnail.GetClientRect(rcList);
  rcList.DeflateRect(25, 25);
  
  // Use monitor 1 to work out the thumbnail sizes
  CRect rcMonitor = m_monitors.rcMonitors.at(0);
  
  m_iThumbnailWidth = rcList.Width();
  
  double dHt = ((double)rcMonitor.Height() / (double)rcMonitor.Width()) * (double)m_iThumbnailWidth;
  m_iThumbnailHeight = (int)dHt;
  </code></pre>
  <p>I fudge it by deflating the rectangle by 25. <code>m_ListThumbnail</code> is a <code>CListCtrl</code> and I am trying to render my thumbnails so that I do not need a horizontal scroll bar.</p>
  <p>When I render the thumbnails of the monitors, I attempt to massage these thumbnail values (incomplete):</p>
  <pre><code>nWidth = m_iThumbnailWidth;
  
  double dHt = ((double)rcCapture.Height() / (double)rcCapture.Width()) * (double)m_iThumbnailWidth;
  nHeight = (int)dHt;
  
  if (nHeight &gt; m_iThumbnailHeight)
  {
      AfxMessageBox(L&quot;Need to investigate!&quot;);
  }
  </code></pre>
  <p>Where <code>rcCapture</code> is the size of the monitor.</p>
  <p>If I remove the <code>DeflateRect</code> line, my window displays like this:</p>
  <p><a href="https://i.stack.imgur.com/s1IOK.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s1IOK.jpg" alt="enter image description here" /></a></p>
  <p>As you can see, it is note as I expected. There is a horizontal scroll bar and I have to resize quite a bit to see the thumbnail:</p>
  <p><a href="https://i.stack.imgur.com/4xjx1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4xjx1.jpg" alt="enter image description here" /></a></p>
  <p>All I want to compute is a set of thumbnail dimensions so that the scaled down monitor image is going to fit in the <code>CListCtrl</code>. I don't really want the user to have to resize the window.</p>
  <hr />
  <h2>Update</h2>
  <p>With my adjusted code which now uses the primary monitor aspect ratio to work out the thumbnail sizes (as added above) renders the app with better whitespace:</p>
  <p><a href="https://i.stack.imgur.com/swuSh.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/swuSh.jpg" alt="enter image description here" /></a></p>
  <p>That was the reason of the extra space at the bottom because the monitors were 16:9 and I was squishing into 4:3. So that is fixed.</p>
  <p>But as you can see, using the <code>CListCtrl</code> client width is not sufficient.</p>
  <hr />
  <h2>Update</h2>
  <p>This is the rendering code:</p>
  <pre><code>// Set the mode first!
  SetStretchBltMode(dcImage, COLORONCOLOR);
  
  int iTop = (m_iThumbnailHeight - nHeight) / 2;
  
  // Copy (and resize)
  bRet = ::StretchBlt(dcImage, 0, iTop,
      nWidth, 
      nHeight, 
      dcScreen.m_hDC, 
      rcCapture.left, 
      rcCapture.top, 
      rcCapture.Width(), 
      rcCapture.Height(), SRCCOPY | CAPTUREBLT);
  </code></pre>