So I’m working on an editor-style application using C++ / MFC in Visual Studio 2008.
The default wizard project for a visual studio style application is full of useful goodness, but doesn’t address everything, and even a few MFC books I found don’t mention this particular question.
How do you go about getting a property viewer using CMFCPropertyGridProperty that displays a floating point value to limit the number of decimal places it shows? Right now, you seem to get 6 decimal places on a float value (constructed using a floating point _variant_t). Is there any way to change this?
The class
CMFCPropertyGridPropertyhas a virtual function calledFormatProperty(). This function returns aCStringobject that contains the string representation of the property’s value. It is called by the framework when the property value needs to be displayed.Since the function is virtual, you can derive your own property class from
CMFCPropertyGridPropertyand override that function so that the base class’s implementation will be invoked in the general case, while your own formatting logic will be applied when thecorresponding variant has type
VT_R4(float) orVT_R8(double).Something like this:
Then, you could pass instances of your own property class
CMyPropertytoCMFCPropertyGrid‘s functionAddProperty().