The first step in implementing CircleOffset functionality is to add the CircleOffset property to the control.
To add the CircleOffset property
The Add Property dialog box appears.
CircleOffset
.The Get function and Set function edit controls appear, replacing the Variable name and Notification function edit controls.
This returns you to the Automation tab. Notice that the implementation of the CircleOffset property appears as:
Implementation:
short GetCircleOffset();
void SetCircleOffset(short nNewValue);
ClassWizard creates the appropriate code to add the CircleOffset property to CCircCtrl
and to CIRC.ODL. Because CircleOffset is a Get/Set property type, ClassWizard modifies the CCircCtrl
class's dispatch map to include a DISP_PROPERTY_EX macro entry:
BEGIN_DISPATCH_MAP(CCircCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CCircCtrl)
DISP_PROPERTY_NOTIFY(CCircCtrl, "CircleShape",
m_circleShape, OnCircleShapeChanged, VT_BOOL)
DISP_PROPERTY_EX(CCircCtrl, "CircleOffset",
GetCircleOffset, SetCircleOffset, VT_I2)
DISP_STOCKPROP_BACKCOLOR()
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CCircCtrl, "AboutBox",
DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
The DISP_PROPERTY_EX macro associates the CircleOffset property name with its corresponding CCircCtrl
class's Get and Set methods, GetCircleOffset
and SetCircleOffset
. The type of the property value is specified as VT_I2, which corresponds to short.
ClassWizard also adds a declaration for the GetCircleOffset
and SetCircleOffset
functions in CIRCCTL.H and also adds their function templates in CIRCCTL.CPP:
short CCircCtrl::GetCircleOffset()
{
// TODO: Add your property handler here
return 0;
}
void CCircCtrl::SetCircleOffset(short nNewValue)
{
// TODO: Add your property handler here
SetModifiedFlag();
}
You will modify the SetCircleOffset
function to perform offset validation later in this lesson.
Because ClassWizard only creates the Get and Set functions, you must add a member variable to the CCircCtrl
class to keep track of the actual value of the CircleOffset property. The Get and Set methods will query and modify this variable. You can add this variable by modifying the declaration of the CCircCtrl
class in CIRCCTL.H. Add the member variable in the protected section after the destructor.
Add the following line of code in CIRCCTL.H:
short m_circleOffset;
as shown in the following code example:
class CCircCtrl : public COleControl
{
...
protected:
~CCircCtrl();
void GetDrawRect(CRect* rc);
short m_circleOffset;
...
};
Modify the Get method created by ClassWizard, GetCircleOffset
, in CIRCCTL.CPP to return the value of this new variable (the //TODO comment line can be removed):
short CCircCtrl::GetCircleOffset()
{
return m_circleOffset;
}