Adding the Stock Properties

Use ClassWizard to add the stock Caption, Font, and ForeColor properties to the Circle control.

To add the stock properties

  1. On the View menu, click ClassWizard.

  2. Click the Automation tab.

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

  4. Click Add Property.

    The Add Property dialog box appears.

  5. From the External name drop-down combo box, select Caption.

  6. Under Implementation, select Stock (it may already be selected).

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

  8. Click Add Property.

  9. From the External name drop-down combo box, select Font.

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

  11. Click Add Property.

  12. From the External name drop-down combo box, select ForeColor.

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

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

    Implementation:
    Stock Property
    
  14. Click OK to confirm your choices and close ClassWizard.

ClassWizard creates the code to add the Caption, Font, and ForeColor properties, modifying both the CCircCtrl class and the CIRC.ODL file.

ClassWizard modifies the CCircCtrl class dispatch map in CIRCCTL.CPP to add the DISP_STOCKPROP_CAPTION macro entry for each property:

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()
    DISP_STOCKPROP_CAPTION()
    DISP_STOCKPROP_FONT()
    DISP_STOCKPROP_FORECOLOR()
    DISP_FUNCTION_ID(CCircCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
    //}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()

The DISP_STOCKPROP_CAPTION macro enables the stock Caption property in the Circle control, implemented as a Get/Set property. Note that the Caption property is an alias for the stock Text property. The Get and Set methods, and notification function for the Caption property are the GetText, SetText, and OnTextChanged functions in class COleControl.

The OnTextChanged function is invoked when the Caption property is modified through the SetText function. By default, OnTextChanged simply invalidates the control.

Stock property notification functions such as OnTextChanged can be overridden in the descendent control class. For example, you may wish to provide an optimal solution for redrawing the caption other than invalidating the control, which forces the whole control to repaint.

In addition to the GetText function, the Caption property can be accessed directly through the InternalGetText function of COleControl. InternalGetText is useful when the control developer accesses the Caption property internally, for example, from the control’s OnDraw function. The CCircCtrl::OnDraw function will be changed to use the InternalGetText function to draw the caption text.

The Circle control uses the font information contained in the stock Font property to draw the caption text. The Font property is actually a pointer to a font object that is encapsulated by class CFontHolder. The font object contains several properties that describe the current font. These properties are accessible through the font object’s IDispatch interface.

Similar to the Caption property, the Font property is implemented as a Get/Set property. The Font property supports a notification function called OnFontChanged, which is defined in COleControl. By default, this function invalidates the control. OnFontChanged can be overridden in the control class to provide an optimal solution to reflecting the font change.

The stock ForeColor property contains the foreground color that the control uses to paint the caption text. Like the stock BackColor property, the ForeColor property is a Get/Set property type.