Available in the LEADTOOLS Imaging toolkit. |
FilePage Event Example for C++ 4.0 and later
This example shows how the FilePage event can be used to size and position a lead control when an image is loaded.
void CTutorDlg::OnFilePageLead1()
{
float HeightFactor, WidthFactor; // Factors for aspect ratio
float HeightAllowed, WidthAllowed; // Maximum width and height
float Width, Height, Left, Top; // Variables for control dimensions
/**********************************************/
// 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.
HeightFactor = m_Lead1.GetInfoHeight();
WidthFactor = m_Lead1.GetInfoWidth();
CRect rcWindow;
GetClientRect(rcWindow);
HeightAllowed = rcWindow.Height() * 3.0f / 4;
WidthAllowed = rcWindow.Width() * 3.0f / 4;
// 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)
{
Left = rcWindow.Width() / 8.0f;
Width = WidthAllowed;
Height = (Width * HeightFactor) / WidthFactor;
Top = (rcWindow.Height() - Height) / 2;
}
else
{
Top = rcWindow.Height() / 8.0f;
Height = HeightAllowed;
Width = (Height * WidthFactor) / HeightFactor;
Left = (rcWindow.Width() - Width) / 2;
}
rcWindow.SetRect(0, 0, (int) Width, (int) Height);
rcWindow.OffsetRect((int) Left, (int) Top);
m_Lead1.MoveWindow(rcWindow);
// Turn off scroll bars to make sure we use the full client area.
m_Lead1.SetAutoScroll(FALSE);
// Set the image display size to match the LEAD control
m_Lead1.SetDstRect(0.0f, 0.0f, m_Lead1.GetScaleWidth(), m_Lead1.GetScaleHeight());
m_Lead1.SetDstClipRect(0.0f, 0.0f, m_Lead1.GetScaleWidth(), m_Lead1.GetScaleHeight());
}