Zooming Out and Zooming In (C++ 5.0 and later)

Take the following steps to add code that can reduce and enlarge the displayed size of the image. This demonstrates the scaling properties that are normally used for zooming in and zooming out. It emphasizes the relationship of the displayed rectangle to the LEAD RasterView control.

1.

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

2.

Go to the Project WorkSpace and click the ResourceView tab.

3.

Double-click Dialog and double-click IDD_TUTOR_DIALOG to bring up the application's dialog box.

4.

image\btncmd.gif Add two command buttons to your form and name them as follows:

 

ID

Caption

 

IDC_ZOOMIN

Zoom In

 

IDC_ZOOMOUT

Zoom Out

5.

Press Ctrl-F4 to close all windows back to the Project Workspace.

6.

To add code for the Zoom Out button, press Ctrl-W to go to the MFC Class Wizard; then do the following:

 

a.

Click the Message Maps tab.

 

b.

In the Class Name combo box, select CTutorDlg.

 

c.

In the Object IDs list box, select IDC_ZOOMOUT.

 

d.

In the Messages list box, select BN_CLICKED.

 

e.

Click the Add function button. Choose OK for the default function name (OnZoomout).

 

f.

Click the Edit Code button, and enter the following code:

m_LEADRasterView1.SetAutoSetRects( TRUE);
m_LEADRasterView1.SetPaintSizeMode( PAINTSIZEMODE_ZOOM);
if (m_LEADRasterView1.GetPaintZoomFactor() > 10)
{
   m_LEADRasterView1.SetPaintZoomFactor(m_LEADRasterView1.GetPaintZoomFactor() - 10);
}

7.

To add code for the Zoom In button, press Ctrl-W to go to the MFC Class Wizard; then do the following:

 

a.

Click the Message Maps tab.

 

b.

In the Class Name combo box, select CTutorDlg.

 

c.

In the Object IDs list box, select IDC_ZOOMIN.

 

d.

In the Messages list box, select BN_CLICKED.

 

e.

Click the Add function button. Choose OK for the default function name (OnZoomIn).

 

f.

Click the Edit Code button, and enter the following code:

m_LEADRasterView1.SetAutoSetRects( TRUE);
m_LEADRasterView1.SetPaintSizeMode( PAINTSIZEMODE_ZOOM);
m_LEADRasterView1.SetPaintZoomFactor(m_LEADRasterView1.GetPaintZoomFactor() + 10);

8.

Rebuild and run the application.