Adding the CircleShape Property

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

  1. On the View menu, click ClassWizard.

  2. Click the Automation tab.

  3. From the Class name drop-down list box, select CCircCtrl.

  4. Click Add Property.

    The Add Property dialog box appears.

  5. In the edit control of the External name drop-down combo box, type CircleShape.

  6. Under Implementation, select Member variable.

  7. From the Type list box, select BOOL.

  8. Verify that the Variable name edit control contains m_circleShape.

  9. Verify that the Notification function edit control contains OnCircleShapeChanged.

  10. Click OK to close the Add Property dialog box.

    This returns you to the  Automation tab. Notice that the implementation of the CircleShape property appears as:

    Implementation:
    BOOL m_circleShape;
    void OnCircleShapeChanged();
    
  11. Click OK to confirm your choices and close ClassWizard.

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.