Using a PanWindow (Visual C++ 5.0 or later)

Take the following steps to start a project and to add some code that opens and displays an image file and allows you to bring up a PanWindow.

1.

Start a new project as follows:

 

Run Microsoft Visual C++ 5.0, select the File >New menu option, and do the following:

 

a.

Click the Projects tab.

 

b.

Select MFC AppWizard (exe) as the project type

 

c.

In the Project name text box, specify pan.

 

d.

In the Location text box, specify the path of the project.

 

e.

Click the OK button.

2.

In the Step 1 dialog box, do the following:

 

a.

Select Dialog based.

 

b.

Click the Next button.

3.

In the Step 2 of 4 dialog box, do the following:

 

a.

Ensure that About Box is selected.

 

b.

Ensure that 3D controls is selected.

 

c.

Select ActiveX controls.

 

d.

Click the Next button.

4.

In the Step 3 of 4 dialog box, do the following:

 

a.

For comments, ensure that Yes, Please is selected.

 

b.

For how to use the MFC library, select As a shared DLL.

 

c.

Click the Next button.

5.

In the Step 4 of 4 dialog box, just click Finish.

6.

Read New Project Information, and click OK. (The AppWizard creates the project files and opens the project.)

7.

Add #import and #include statements to your program so you can access the LEAD COM constants and classes:

 

a.

In the Project Workspace, click the FileView tab.

 

b.

Double-click the mditutor files folder to open it.

 

c.

Double-click the Header Files folder to open it.

 

d.

Double-click the StdAfx.h file to edit it.

 

e.

Add the following lines to the end of the file (keep in mind, you may have to change the path to where the dll's reside):

#import "c:\\winnt\\system32\\ltrvr14n.dll"  no_namespace, named_guids
#import "c:\\winnt\\system32\\ltr14n.dll" no_namespace, named_guids
#import "c:\\winnt\\system32\\ltrvw14n.ocx" no_namespace, named_guids
#import "c:\\winnt\\system32\\ltrio14n.dll" no_namespace, named_guids
#import "c:\\winnt\\system32\\ltrpr14n.dll" no_namespace, named_guids
#include "leadraster.h"

8.

Add a LEAD RasterView control to the main window as follows:

 

a.

In the Project Workspace, click the ResourceView tab.

 

b.

Double-click the mditutor resources folder to open it.

 

c.

Double-click the Pan folder to open it.

 

d.

Double-click IDD_PAN_DIALOG to design the form.

 

e.

Select the TODO... text control; then press the Delete key to delete it.

 

f.

From the main menu, select Project > Add to project > Components and Controls. (The Component Gallery appears.)

 

g.

Click the Registered ActiveX Contols.

 

h.

Double-click the LEAD RasterView Control icon. (The Confirm Classes dialog box appears.)

 

i.

Ensure that both CLEADRasterView, CLEADRaster, and CPicture are checked.

 

j.

Click OK to complete the selection; then click Close to close the Component Gallery. (The LEAD RasterView control appears in the Controls toolbar.)

 

k.

image\btnlead.gif Click the LEAD RasterView control icon; then size and position the control as you want it to appear at run time.

 

l.

Use the right mouse button to edit the properties of the new LEAD RasterView control.

 

m.

Change the ID to IDC_LEADRASTERVIEW1.

9.

Add a command button to your form and name it as follows:

 

ID

Caption

 

IDC_PANWIN

Show Pan Window

10.

Add a Check box control to the main window and set the ID and Caption as follows:

 

ID

Caption

 

IDC_CHECK1

Pan Window

11.

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

12.

Do the following to add m_LEADRasterView1 and m_Check1 to the CPanDlg class and link the variable to the controls using dynamic data exchange:

 

a.

Press Ctrl-W. (The MFC ClassWizard dialog box appears.)

 

b.

Click the Member Variables tab.

 

c.

In the Class Name box, select CPanDlg.

 

d.

In the Control IDs list, select IDC_LEADRASTERVIEW1.

 

e.

Click the Add Variable... button.

 

f.

Specify m_LEADRasterView1 as the variable name, and control as the category.

 

g.

Click OK to close the dialog box.

 

h.

Back in MFC Wizard, go to the Member Variables tab, and ensure CPanDlg is in the Class Name box.

 

i.

In the Control IDs list, select IDC_CHECK1.

 

j.

Click the Add Variable... button.

 

k.

Specify m_Check1 as the variable name, and control as the category.

 

l.

Click OK to close the dialog box, and click OK to close the MFC ClassWizard.

13.

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 CPanDlg.

 

c.

In the Object IDs list box, select IDC_PANWIN.

 

d.

In the Messages list box, select BN_CLICKED.

 

e.

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

 

f.

Click the Edit Code button and enter the following code:

/*set the location of the PanWindow*/
   m_LEADRasterView1.SetPanWinX(100.0f);
   m_LEADRasterView1.SetPanWinY(100.0f);
   /*set the size of the PanWindow*/
   m_LEADRasterView1.SetPanWinWidth(150.0f);
   m_LEADRasterView1.SetPanWinHeight(200.0f);
   /*set the type of mouse pointer*/
   m_LEADRasterView1.SetPanWinPointer (12);
   
   m_LEADRasterView1.SetPanWinTitle ("PanWindow");
   m_LEADRasterView1.SetPanWinRectColor (RGB(0, 0, 255));
   m_LEADRasterView1.SetPanWinSysMenu (1);
   /*use the settings for LEADRASTERVIEW1*/
   m_LEADRasterView1.SetPanWinPaintPalette (m_LEADRasterView1.GetPaintPalette());
   m_LEADRasterView1.SetPanWinBitonalScaling (m_LEADRasterView1.GetBitonalScaling ());
   m_LEADRasterView1.SetPanWinPaintScaling(m_LEADRasterView1.GetPaintScaling());
   m_LEADRasterView1.SetPanWinPaintDither (m_LEADRasterView1.GetPaintDither ());
   m_LEADRasterView1.ShowPanWin(TRUE);
   m_Check1.SetCheck(TRUE);

14.

Add the following line to the OnInitDialog procedure in the PanDlg.cpp file, following : // TODO: Add extra initialization here

   ILEADRasterIO *pRasterIO=NULL;
   CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL,
                    IID_ILEADRasterIO, (void**)&pRasterIO);
   pRasterIO->Load(m_LEADRasterView1.GetRaster(),
                   "v:\\images\\eagle.cmp", 0, 0, 1);
   pRasterIO->Release();

15.

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 CPanDlg.

 

c.

In the Object IDs list box, select IDC_LEADRASTERVIEW1.

 

d.

In the Messages list box, select PanWin.

 

e.

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

 

f.

Click the Edit Code button and code the OnPanWin procedure as follows:

if (iFlag == PANWIN_DESTROYED)
{
   m_Check1.SetCheck(FALSE);
}

16.

On the main menu, select Build> Build pan.exe to build the project.

17.

On the main menu, select Build> Execute pan.exe to run the project.