PaintWhileLoad example for C++ 4.0 and later

This example causes the LEAD control to paint the image as it loads.

m_Lead1.SetPaintWhileLoad(TRUE);
// Get information about the image so that we can size the control.
m_Lead1.GetFileInfo("c:\\lead\\images\\image2.cmp", 0, 0 );
// Set the variables used for preserving the aspect ratio.
// Allow for a border of 1/8 of the form size.
// The units of measure do not matter, since we are calculating proportions.
CRect rcWindow;
CRect rcControl;
GetClientRect(&rcWindow);
GetWindowRect(&rcControl);
float HeightFactor = m_Lead1.GetInfoHeight();
float WidthFactor = m_Lead1.GetInfoWidth();
float HeightAllowed = rcWindow.Height() * 3.0f / 4.0f;
float WidthAllowed = rcWindow.Width() * 3.0f / 4.0f;
// Center the LEAD control on the form, preserving the aspect ratio.
// Check to see if using the maximum width will make the image too tall.
// Set the dimensions based on the result.
if (((WidthAllowed * HeightFactor) / WidthFactor) < HeightAllowed)
{
  rcControl.SetRect(0, 0,
    (int) WidthAllowed,
    (int) ((WidthAllowed * HeightFactor) / WidthFactor));
  rcControl.OffsetRect(rcWindow.Width() / 8,
(rcWindow.Height() - rcControl.Height()) / 2);
}
else
{
  rcControl.SetRect(0, 0,
   (int) ((HeightAllowed * WidthFactor) / HeightFactor),
   (int) HeightAllowed);
  rcControl.OffsetRect((rcWindow.Width() - rcControl.Width()) / 2,
rcWindow.Height() / 8);
}
m_Lead1.MoveWindow(rcControl);
// Set the image display sizes to match the LEAD controls
float ImageHeight = m_Lead1.GetScaleHeight();
float ImageWidth = m_Lead1.GetScaleWidth();
float BitmapHeight = m_Lead1.GetInfoHeight();
float BitmapWidth = m_Lead1.GetInfoWidth();
m_Lead1.SetSrcRect(0.0f, 0.0f, BitmapWidth, BitmapHeight);
m_Lead1.SetSrcClipRect(0.0f, 0.0f, BitmapWidth, BitmapHeight);
m_Lead1.SetDstRect(0.0f, 0.0f, ImageWidth, ImageHeight);
m_Lead1.SetDstClipRect(0.0f, 0.0f, ImageWidth, ImageHeight);
// Turn off the automatic adjustment of display rectangles
m_Lead1.SetAutoSetRects(FALSE);
// Load the file
m_Lead1.Load("c:\\lead\\images\\image2.cmp", 0, 0, 1);
// Turn on the automatic adjustment of display rectangles for future use
m_Lead1.SetAutoSetRects(TRUE);