Now that the property page has controls for displaying and modifying properties, the controls need to be linked to the properties. You can link controls in the property page with properties by using a shortcut to the Add Member Variable dialog box in ClassWizard.
To link the property page controls to properties
The Add Member Variable dialog box of ClassWizard appears.
caption
, so the edit control contains m_caption.If you were to open ClassWizard, the Member Variables tab would contain the new member variable mapping for the Caption property, as shown below:
Control IDs: Type Member
IDC_CAPTION CString m_caption
IDC_CIRCLEOFFSET
IDC_CIRCLESHAPE
Member variable name: m_circleOffset
Category: Value
Variable type: int
Optional property name: CircleOffset
Member variable name: m_circleShape
Category: Value
Variable type: BOOL
Optional property name: CircleShape
If you were to open ClassWizard, the Member Variables tab would contain the new member variable mapping for the CircleShape property, as shown below:
Control IDs: Type Member
IDC_CAPTION CString m_caption
IDC_CIRCLEOFFSET int m_circleOffset
IDC_CIRCLESHAPE BOOL m_circleShape
ClassWizard adds the member variables to the CCircPropPage
class. ClassWizard also adds functions to the CCircPropPage
class to initialize the member variables and to handle the exchange of data between the dialog controls, the member variables, and the properties.
The m_caption
, m_circleOffset
, and m_circleShape
member variables are declared in CIRCPPG.H:
class CCircPropPage : public COlePropertyPage
{
...
//{{AFX_DATA(CCircPropPage)
...
CString m_caption;
int m_circleOffset;
BOOL m_circleShape;
//}}AFX_DATA
...
};
The member variables are initialized in the constructor for the CCircPropPage
class, the CCircPropPage
function in CIRCPPG.CPP:
CCircPropPage::CCircPropPage() :
COlePropertyPage(IDD, IDS_CIRCCTRL_PPG_CAPTION)
{
//{{AFX_DATA_INIT(CCircPropPage)
m_caption = _T("");
m_circleOffset = 0;
m_circleShape = FALSE;
//}}AFX_DATA_INIT
}
Notice that strings assigned to member variables are first passed through the _T macro. This is the same macro used for string parameters to PX_ functions in CCircCtrl::DoPropExchange
. The _T macro is used to maintain compatibility between different string representations, and it must be used for all literal strings in an ActiveX control project.
Data transfer is handled by the DDP_ and DDX_ macros in the DoDataExchange
function in CIRCPPG.CPP:
void CCircPropPage::DoDataExchange(CDataExchange* pDX)
{
//{{AFX_DATA_MAP(CCircPropPage)
DDP_Text(pDX, IDC_CAPTION, m_caption, _T("Caption"));
DDX_Text(pDX, IDC_CAPTION, m_caption);
DDP_Text(pDX, IDC_CIRCLEOFFSET, m_circleOffset, _T("CircleOffset"));
DDX_Text(pDX, IDC_CIRCLEOFFSET, m_circleOffset);
DDP_Check(pDX, IDC_CIRCLESHAPE, m_circleShape, _T("CircleShape"));
DDX_Check(pDX, IDC_CIRCLESHAPE, m_circleShape);
//}}AFX_DATA_MAP
DDP_PostProcessing(pDX);
}
The DDX_ macros are the same macros used for standard MFC dialog boxes. They synchronize dialog controls with dialog member variables. The DDP_macros are used only in ActiveX control property pages. They synchronize property page dialog member variables with specific control properties. Translations between an edit control and a short value and between a check box and a BOOL value are automatic. Similar to strings assigned to member variables, strings passed as parameters to DDP_ macros are first passed through the _T macro.
The Circle control now has a general property page that can be used to display and modify the values of several of its properties. The IDC_CAPTION
edit control, IDC_CIRCLEOFFSET
edit control, and IDC_CIRCLESHAPE
check box are linked through property page member variables to the Caption, CircleOffset, and CircleShape properties, respectively. Between the default property page added in this lesson and the stock color and font property pages added earlier, all Circle control properties can now be accessed through property pages.