Zooming In on a Selection (C++ 4.0 and later)

Take the following steps to add code that lets you select an area with a mouse, and zoom in on the selected area.

1. Start with the project that you created in Loading and Displaying an Image.

2. To add the code for LEAD events, do the following:

a. Press Ctrl-W to go to the MFC ClassWizard.

b. In the Class Name combo box, select CTutorDlg.

c. In the Object IDs list box, select IDC_LEAD1.

d. Continue with the remaining steps for each event.

3. In the MFC ClassWizard, double-click the MouseDown event and add code as follows:

void CTutorDlg::OnMouseDownLead1(short Button, short Shift, long X, long Y) 
{
  m_Lead1.SetAutoRubberBand(TRUE);
  m_Lead1.SetMousePointer(2);
}

4. In the MFC ClassWizard, double-click the RubberBand event and add code as follows:

void CMfc40Dlg::OnRubberBandLead1() 
{
  float zoomleft;
  float zoomtop;
  float zoomwidth;
  float zoomheight;

  m_Lead1.SetMousePointer(0);

  //Zoom in on the selection.
  zoomleft = m_Lead1.GetRubberBandLeft();
  zoomtop = m_Lead1.GetRubberBandTop();
  zoomwidth = m_Lead1.GetRubberBandWidth();
  zoomheight = m_Lead1.GetRubberBandHeight();

  //zoom in on the rectangle defined by the rubberband
  m_Lead1.ZoomToRect(zoomleft, zoomtop, zoomwidth, zoomheight);
  m_Lead1.ForceRepaint();
}

5. Rebuild and run the application.