Some days ago, I was trying to implement a method that would detect when a value was updated in my Properties Window (CPropertiesWnd
) and do some other stuff in a MFC application of mine. Since I was mostly using CMFCPropertyGridProperty
instances in order to deal with the information contained in my Properties Window, I've decided to implement the method BOOL CMFCPropertyGridProperty::OnUpdateValue()
(virtual), which is called automatically by the framework whenever something in my property grid has changed. So, since I am not able to modify the CMFCPropertyGridProperty
class (and other files like afxpropertygridctrl.h
), I've created an auxiliary class to do so:
#pragma once
// CMFCPropertyGridPropertyAux
class CMFCPropertyGridPropertyAux : public CMFCPropertyGridProperty
{
public:
CMFCPropertyGridPropertyAux(const CString& strGroupName, DWORD_PTR dwData=0, BOOL bIsValueList=FALSE);
CMFCPropertyGridPropertyAux(const CString& strName, const COleVariant& varValue, LPCTSTR lpszDescr = NULL, DWORD_PTR dwData = 0,
LPCTSTR lpszEditMask = NULL, LPCTSTR lpszEditTemplate = NULL, LPCTSTR lpszValidChars = NULL);
virtual ~CMFCPropertyGridPropertyAux();
BOOL OnUpdateValue();
};
// MFCPropertyGridPropertyAux.cpp : implementation file
//
#include "stdafx.h"
#include "MFCProject.h"
#include "MFCPropertyGridPropertyAux.h"
// CMFCPropertyGridPropertyAux
CMFCPropertyGridPropertyAux::CMFCPropertyGridPropertyAux(const CString& strGroupName, DWORD_PTR dwData,BOOL bIsValueList):CMFCPropertyGridProperty(strGroupName, dwData, bIsValueList)
{
}
CMFCPropertyGridPropertyAux::CMFCPropertyGridPropertyAux(const CString& strName, const COleVariant& varValue, LPCTSTR lpszDescr, DWORD_PTR dwData,
LPCTSTR lpszEditMask, LPCTSTR lpszEditTemplate, LPCTSTR lpszValidChars):CMFCPropertyGridProperty(strName, varValue, lpszDescr, dwData, lpszEditMask, lpszEditTemplate, lpszValidChars)
{
}
CMFCPropertyGridPropertyAux::~CMFCPropertyGridPropertyAux()
{
}
BOOL CMFCPropertyGridPropertyAux::OnUpdateValue() //virtual method implementation
{
AfxMessageBox(L"Value Changed");
//do other stuff
return true;
}
I was able to detect whenever a property was in fact changed, but there were a few bugs (like erasing the whole updated information after the appearance of the MessageBox), which are possibly related to the other methods and attributes from the CMFCPropertyGridProperty
that still weren't implemented in this auxiliary class.
I was wondering: It will be a whopping job to implement everything that is contained in the CMFCPropertyGridProperty
class in my auxiliary class (just like I've done with the constructors). Should there be an strategy regarding OOP that should do the trick? Also, I don't know if my approach is the best one. I mean, is there a simplier way in order to implement the BOOL CMFCPropertyGridProperty::OnUpdateValue()
without rewriting codes from another class? Any ideas are welcome!