FilePage Event Example for C++ 5.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.
//NOTE: This is not a complete example for handing events, some steps have been omitted.
//For a complete example of how to handle events, refer to the example
//Updating a Gauge and Detecting a User Interrupt.
void CRasterIOSink::OnFilePage(void)
{
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_pDlg->m_pRasterIO->GetInfoHeight();
WidthFactor = m_pDlg->m_pRasterIO->GetInfoWidth();
CRect rcWindow;
m_pDlg->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_pDlg->m_LEADRasterView1.MoveWindow(rcWindow);
// Turn off scroll bars to make sure we use the full client area.
m_pDlg->m_LEADRasterView1.SetAutoScroll(FALSE);
// Set the image display size to match the LEAD control
m_pDlg->m_LEADRasterView1.SetDstRect(0.0f, 0.0f,
m_pDlg->m_LEADRasterView1.GetScaleWidth(),
m_pDlg->m_LEADRasterView1.GetScaleHeight());
m_pDlg->m_LEADRasterView1.SetDstClipRect(0.0f, 0.0f,
m_pDlg->m_LEADRasterView1.GetScaleWidth(),
m_pDlg->m_LEADRasterView1.GetScaleHeight());
}