Adding the FlashColor Property

The FlashColor property holds the color value that flashes within the control circle. Windows represents a color as a 32-bit value, defined as a COLORREF type. The ActiveX control classes do not directly support the COLORREF type, but they do support an OLE_COLOR type that can hold the required information. Thus, the FlashColor property is defined as an OLE_COLOR type.

The FlashColor property requires no special processing when its value is changed or accessed. For this reason, FlashColor can be defined as a simple member variable property.

To add the FlashColor 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 FlashColor.

  6. From the Type list box, select OLE_COLOR.

  7. Under Implementation, select Member variable (it may already be selected).

  8. Verify that the Notification function edit control contains OnFlashColorChanged and that the Variable name edit control contains m_flashColor.

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

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

    Implementation:
    OLE_COLOR m_flashColor;
    void OnFlashColorChanged();
    
  10. Click OK to confirm your choices and close ClassWizard.

ClassWizard creates the code to add the FlashColor property, modifying both the CCircCtrl class and the CIRC.ODL file. Because FlashColor is a member variable property type, ClassWizard modifies the CCircCtrl class's dispatch map in CIRCCTL.CPP to include a DISP_PROPERTY_NOTIFY macro entry:

BEGIN_DISPATCH_MAP(CCircCtrl, COleControl)
    //{{AFX_DISPATCH_MAP(CCircCtrl)
    DISP_PROPERTY_NOTIFY(CCircCtrl, "FlashColor",
        m_flashColor, OnFlashColorChanged, VT_COLOR)
    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_NOTIFY macro associates the FlashColor property name with the following:

ClassWizard also adds a declaration for the OnFlashColorChanged notification function in CIRCCTL.H and a function template in CIRCCTL.CPP:

void CCircCtrl::OnFlashColorChanged()
{
    // TODO: Add notification handler code
    SetModifiedFlag();
}