Article ID: 140592 - Last Review: November 21, 2006 - Revision: 4.2 How To Implement Per-Property Browsing for a Custom PropertyThis article was previously published under Q140592 On This PageSUMMARY
This article illustrates how to implement per-property browsing for a
custom property present in an OLE control. The custom property can be
manipulated either in a property page that implements editing of this
property or directly in the property browser provided by the container
application. When the property browser of Microsoft Visual Basic is used, for example, selecting the custom property for editing displays a three-dot button next to the property's value. Clicking the three-dot button displays the property page associated with the property--if one is available. MORE INFORMATION
An OLE control container typically provides some kind of user interface
where the user can manipulate the properties of the control. Some
containers may need to browse individual property values rather than groups
of property values, which is a technique commonly referred to as
per-property browsing. An OLE control can support non-default, per-property
browsing by implementing IPerPropertyBrowsing. Otherwise, the container
application uses the type information. When an OLE control's property is manipulated using the property browser provided by a container application, the container queries to find out if the control supports IPerPropertyBrowsing. If an interface pointer can be successfully obtained, the container then makes a call to IPerPropertyBrowsing::MapPropertyToPage to obtain the CLSID of the property page that implements editing of this particular property. If this method returns S_OK or S_FALSE, the container creates a property frame with the property page corresponding to the returned CLSID in it. The success return codes (S_OK and S_FALSE) from IPerPropertyBrowsing::MapPropertyToPage specify whether or not a property can be edited outside the property page identified by the CLSID. A return code of S_FALSE implies that this particular property can only be edited through a specific property page -- not outside this property page. For example, the property cannot be directly edited in the property browser of Visual Basic. If the method returns S_OK, then the property can be manipulated outside the property page. Please refer to the CDK Books Online for more information on MapPropertyToPage and its return values. The sample code in this article can be added to an OLE control to implement a custom property that can only be edited using a specific property page -- not outside the property page. The code overrides two member functions of COleControl, namely OnMapPropertyToPage and OnGetDisplayString. The MFC framework calls OnMapPropertyToPage to obtain the CLSID of a property page that implements editing of the property identified by a dispID. The framework calls OnGetDisplayString to obtain a string representing the property's value to be displayed in a container-supplied property browser. Steps to Add Custom Property Named MyProp to an OLE ControlFor the code to work, the ClassWizard must have been used to add a custom property named MyProp to an OLE control. The following steps illustrate how to add a custom property named MyProp using ClassWizard. This will use the Get/Set Methods implementation:
Sample CodeOnce the MyProp property is added, the following code can be used to display that property in the property browser provided by Visual Basic:APPLIES TO
| Article Translations
|
Back to the top
