HOWTO: How to Set Default Values for Stock Properties in OLE Controls
This article was previously published under Q138866 On This PageSUMMARY
When developing an OLE Control, you may decide that some of the properties
should be serialized. This can be accomplished in the DoPropExchange()
method of your COleControl-derived class by using the PX_ functions. The
PX_ functions also allow you to specify a default value for the property,
which is good programming practice. You may also want to give default
values to any stock properties that are used by your control. The
serialization and initialization of stock properties is handled by MFC in
COleControl::DoPropExchange(pPX). To set a default value for a stock
property, you need to work around some of MFC's functionality. This article
explains how to do it.
MORE INFORMATION
When you use the Microsoft Control Developer's Kit (CDK) to create the MFC
framework for an OLE Control, it creates a COleControl-derived class with
an overridden DoPropExchange() member function. By default, the overridden
DoPropExchange() calls COleControl::DoPropExchange(). This in turn calls
COleControl::ExchangeStockProps(), which contains the MFC code for
serializing stock properties. Within this function, MFC uses the COleControl m_dwStockPropMask protected member variable to determine which stock properties you have added with Class Wizard. This mask can be modified in your DoPropExchange() to force MFC to ignore existing stock properties and therefore allow you to add your own code. Ideally you should copy the relevant code already present in COleControl::ExchangeStockProps(), and then modify it as necessary. The following sample code shows how to accomplish this for the Caption stock property by modifying step three of the Circ OLE Control tutorial. Sample CodeREFERENCES
The functions discussed in this article can be found using the Find in
Files feature of Visual C++; in version 2.x within the Cdk32\Src directory
and in version 4.x within the mfc\src subdirectory.
APPLIES TO
| Article Translations
|
Back to the top
