Associating Your Resources with Classes
You now have all your resources created. Next, associate your two new property-pageresources with C++ classes so that you can control them in your program. You also need
a class for your property sheet, which will hold the property pages that you've created.
Follow these steps to create the new classes:
1. Make sure that the Page 1 property page is visible in the dialog box edit area
and then double-click it. If you prefer, choose View, ClassWizard from the menu
bar. The MFC ClassWizard property sheet appears, displaying the Adding a Class
dialog box first discussed in Chapter 2, "Dialogs and Controls."
2. Select the Create New Class option and then click OK. The New Class dialog
box appears.
3. In the Name box, type CPage1. In the Base Class box, select CPropertyPage.
(Don't accidentally select CPropertySheet.) Then click OK to create the class.
You've now associated the property page with an object of the CPropertyPage
class, which means that you can use the object to manipulate the property page as
needed. The CPropertyPage class will be especially important when you learn
about wizards.
4. Select the Member Variables tab of the MFC ClassWizard property sheet. With
IDC_EDIT1 highlighted, click the Add Variable button. The Add Member Variable
dialog box appears.
5. Name the new member variable m_edit, as shown in Figure 12.11, and then click
OK. ClassWizard adds the member variable, which will hold the value of the
property page's control, to the new CPage1 class.
FIG 12.11 ClassWizard makes it easy to connect controls on a dialog box to member variables of the
class representing the dialog box.
6. Click OK on the MFC ClassWizard properties sheet to finalize the creation of
the CPage1 class.
7. Follow steps 1 through 6 for the second property sheet. Name the class CPage2
and add a Boolean member variable called m_check for the IDC_CHECK1 control,
as shown in Figure 12.12.
FIG. 12.12 The second property page needs a Boolean member variable called m_checkbox.
No comments:
Post a Comment