The first step in implementing CircleShape functionality is to add the property to the control. Similar to a stock property, a custom property is added using ClassWizard.
To add the CircleShape property
The Add Property dialog box appears.
CircleShape
.m_circleShape
.OnCircleShapeChanged
.This returns you to the Automation tab. Notice that the implementation of the CircleShape property appears as:
Implementation:
BOOL m_circleShape;
void OnCircleShapeChanged();
ClassWizard creates the appropriate code to add the CircleShape property to the CCircCtrl
class and to the CIRC.ODL file. When adding a DISP_PROPERTY_NOTIFY property type, ClassWizard modifies the CCircCtrl
class's dispatch map by adding a DISP_PROPERTY_NOTIFY macro entry for the property:
BEGIN_DISPATCH_MAP(CCircCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CCircCtrl)
DISP_PROPERTY_NOTIFY(CCircCtrl, "CircleShape",
m_circleShape, OnCircleShapeChanged, VT_BOOL)
DISP_STOCKPROP_BACKCOLOR()
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CCircCtrl, "AboutBox",
DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
The DISP_PROPERTY_NOTIFY macro associates the CircleShape property name with its corresponding CCircCtrl
class member variable (m_circleShape
), as well as the name of the CCircCtrl
class notification function (OnCircleShapeChanged
), which is called whenever the value of CircleShape property is changed. The property type value is specified as VT_BOOL.
ClassWizard also adds a declaration for the OnCircleShapeChanged
notification function in CIRCCTL.H and a function template in CIRCCTL.CPP:
void CCircCtrl::OnCircleShapeChanged()
{
// TODO: Add notification handler code
SetModifiedFlag();
}
You will modify OnCircleShapeChanged
to invalidate the control in Modifying OnCircleShapeChanged, later in this lesson.