CMFCPropertyGridCtrl这个控件当用到掩码时,会有问题.解决办法用其他掩码替代.下面是一个IP掩码处理方法.代码如下
class CMyMaskEditProp : public CMFCPropertyGridProperty
{
public:
CMyMaskEditProp(const CString& strName, const COleVariant& varValue, LPCTSTR lpszDescr = NULL, DWORD_PTR dwData = 0,
LPCTSTR lpszEditMask = NULL, LPCTSTR lpszEditTemplate = NULL, LPCTSTR lpszValidChars = NULL);
virtual BOOL OnUpdateValue();
protected:
virtual CWnd* CreateInPlaceEdit(CRect rectEdit, BOOL& bDefaultFormat);
//virtual BOOL OnSetCursor() const { return FALSE; /* Use default */ }
};
// CMyMaskEditProp class
CMyMaskEditProp::CMyMaskEditProp(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)
{
}
BOOL CMyMaskEditProp::OnUpdateValue()
{
ASSERT_VALID(this);
ASSERT_VALID(m_pWndInPlace);
ASSERT_VALID(m_pWndList);
ASSERT(::IsWindow(m_pWndInPlace->GetSafeHwnd()));
//long lCurrValue = m_varValue.lVal;
CMaskEdit* pWndEdit = (CMaskEdit*) m_pWndInPlace;
CString str;
pWndEdit->GetWindowText(str);
if (str != (char *)(_bstr_t)m_varValue)
{
m_varValue=str;
m_pWndList->OnPropertyChanged(this);
}
return TRUE;
}
CWnd* CMyMaskEditProp::CreateInPlaceEdit(CRect rectEdit, BOOL& bDefaultFormat)
{
CMaskEdit* pWndEdit = new CMaskEdit;
pWndEdit->m_bisTime = FALSE;
pWndEdit->m_isdate = FALSE;
pWndEdit->m_bUseMask = TRUE;
pWndEdit->m_strMask = "000.000.000.000";
pWndEdit->m_strLiteral = "___.___.___.___";
pWndEdit->m_str = "255.255.255.255";
pWndEdit->m_strMaskLiteral = m_varValue.bstrVal;
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);
pWndEdit->SetWindowText((char *)(_bstr_t)m_varValue);
bDefaultFormat = TRUE;
return pWndEdit;
}