Combining Images with Regions (C++ 5.0 and later)

Take the following steps to start a project and to add some code that combines two images with a region:

1. Start a new project as follows:

For C++ 4.x, run Microsoft Developer Studio for Visual C++, select the File >New menu option, select Project Workspace, and click the OK button. In the New Project Workspace dialog box, do the following:

a. In the Type list box, select MFC AppWizard (exe).

b. In the Name text box, specify tutor.

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

d. In the Platforms list box, check Win32.

e. Click the Create button.

For C++ 5.0, 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 tutor.

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 statically linked library.

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 the L_OCX.H files, which define LEAD constants, to your project as follows:

a. In the Project Workspace, click the FileView tab.

b. Double-click the tutor files folder to open it.

c. Double-click the Dependencies folder (the Header Files folder in 5.0) to open it.

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

e. Add the following line to the end of the file:

#include "C:\LEAD\Include\L_OCX.H"

8. Add a LEAD control to the main window as follows:

a. In the Project Workspace, click the ResourceView tab.

b. Double-click the tutor resources folder to open it.

c. Double-click the Dialog folder to open it.

d. Double-click IDD_TUTOR_DIALOG to design the dialog box.

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.

g. Select Registered ActiveX Controls.

h. Double-click the LEAD Main ActiveX Control (16) icon. (The Confirm Classes dialog box appears.)

i. Ensure that CLead, CPicture, and COleFont are checked.

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

k. image\btnlead.gif Click the LEAD 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 control.

m. Change the ID to IDC_LEAD1.

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

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

  1. Change the ID to IDC_LEAD2.

q. Ensure that the Visible radio button is unchecked.

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

10. Do the following to add m_Lead1 and m_Lead2 to the CTutorDlg class and link the variables to the LEAD 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 CTutorDlg.

d. In the Control IDs list, select IDC_LEAD1.

e. Click the Add Variable... button.

f. Specify m_Lead1 as the variable name, and Control as the category.

g. Click OK to close the dialog box.

h. In the Control IDs list, select IDC_LEAD2.

i. Click the Add Variable... button.

j. Specify m_Lead2 as the variable name, and Control as the category.

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

11. Go to the OnInitDialog() function as follows:

a. In the Project Workspace, click the ClassView tab.

b. Double-click the tutor classes folder to open it.

c. Expand the CTutorDlg class.

d. Double-click the OnInitDialog() function to edit it.

12. Edit the OnInitDialog() function to add the following code after the line that says //TODO: Add extra initialization here:

   m_Lead1.Load("c:\\sample1.cmp", 0, 0, 1);
   m_Lead2.Load("c:\\sample2.cmp", 0, 0, 1);

   m_Lead1.SetRgnRect(100, 100, 300, 300, L_RGN_SET);
   m_Lead1.Combine(100, 100, 300, 300, m_Lead2.GetBitmap(), 0, 0, CB_OP_ADD | CB_DST_0);

   m_Lead1.FreeRgn();

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

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