Reputation: 141
I have been trying to validate and update each character in the properties edit box (CMFCPropertyGridCtrl
) which was entered by the user.I searched the MSDN and find function like PushChar()
etc. But those methods didn't solve my problem. Basically I need to implement CEdit::OnChar()
function for the CMFCPropertyGridCtrl
edit boxes.
Upvotes: 2
Views: 909
Reputation: 141
I am going to give the sample code for this. In CustomProperties.h
, Derive a class form CMFCPropertyGridProperty
class CMyEditProp : public CMFCPropertyGridProperty
{
public:
CMyEditProp (const CString& strName, const CString& strValue, LPCTSTR lpszDescr = NULL, DWORD dwData = 0);
protected:
virtual CWnd* CreateInPlaceEdit(CRect rectEdit, BOOL& bDefaultFormat);
virtual CString FormatProperty();
};
Also derive a class from CEdit
and implement a OnChar()
method in it.
class MyEdit:public CEdit
{
public:
void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(!IsCharAlpha(nChar))
return;
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
DECLARE_MESSAGE_MAP()
};
In CustomProperties.cpp
Implement all the methods which were declared in header file.
CMyEditProp ::CPasswordProp(const CString& strName, const CString& strValue, LPCTSTR lpszDescr, DWORD dwData)
: CMFCPropertyGridProperty(strName, (LPCTSTR) strValue, lpszDescr, dwData)
{
}
CWnd* CMyEditProp ::CreateInPlaceEdit(CRect rectEdit, BOOL& bDefaultFormat)
{
MyEdit pWndEdit;
DWORD dwStyle = WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL ;
if (!m_bEnabled || !m_bAllowEdit)
{
dwStyle |= ES_READONLY;
}
pWndEdit.Create(dwStyle, rectEdit, m_pWndList, AFX_PROPLIST_ID_INPLACE);
bDefaultFormat = TRUE;
return &pWndEdit;
}
BEGIN_MESSAGE_MAP(MyEdit,CEdit)
ON_WM_CHAR()
END_MESSAGE_MAP()
This will work like as Edit control and you can validate all the characters entered by the user.
Upvotes: 0
Reputation: 4335
When you provide lpszEditMask
or lpszEditTemplate
or lpszValidChars
parameters to the constructor of a property, the edit control of that property will be a CMFCMaskedEdit
instead of a normal CEdit
. You can confirm what I said on CMFCPropertyGridProperty::CreateInPlaceEdit
implementation.
So, if I was in your place, I would read CMFCMaskedEdit
documentation to know how to input the masking, put a breakpoint on CMFCPropertyGridProperty::CreateInPlaceEdit
to see how it behaves when you supply the lpsz...
arguments and then would come back here to the page to report how had things gone.
Upvotes: 1