PaintWhileLoad example for C++ 5.0 and later
This example causes the LEAD control to paint the image as it loads.
ILEADRasterIO *pRasterIO=NULL;
CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL,
IID_ILEADRasterIO, (void**)&pRasterIO);
m_LEADRasterView1.SetPaintWhileLoad(TRUE);
// Get information about the image so that we can size the control.
pRasterIO->GetFileInfo(m_LEADRasterView1.GetRaster(),
"d:\\lead14\\dist\\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 = pRasterIO->GetInfoHeight();
float WidthFactor = pRasterIO->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_LEADRasterView1.MoveWindow(rcControl);
// Set the image display sizes to match the LEAD controls
float ImageHeight = m_LEADRasterView1.GetScaleHeight();
float ImageWidth = m_LEADRasterView1.GetScaleWidth();
float BitmapHeight = pRasterIO->GetInfoHeight();
float BitmapWidth = pRasterIO->GetInfoWidth();
m_LEADRasterView1.SetSrcRect(0.0f, 0.0f, BitmapWidth, BitmapHeight);
m_LEADRasterView1.SetSrcClipRect(0.0f, 0.0f, BitmapWidth, BitmapHeight);
m_LEADRasterView1.SetDstRect(0.0f, 0.0f, ImageWidth, ImageHeight);
m_LEADRasterView1.SetDstClipRect(0.0f, 0.0f, ImageWidth, ImageHeight);
// Load the file
pRasterIO->Load(m_LEADRasterView1.GetRaster(),
"d:\\lead14\\dist\\images\\image2.cmp", 0, 0, 1);
pRasterIO->Release();