[英]How to insert an edit box into CMFCPropertyGridCtrl for password usage?
我想在CMFCPropertyGridCtrl中插入一个编辑框来输入密码。 但CMFCPropertyGridProperty只能创建普通的编辑框。 如何为密码使用创建一个新的?
从CMFCPropertyGridProperty
派生一个新类并覆盖两个函数: OnDrawValue()
和CreateInPlaceEdit()
。
代码原型可能如下所示:
void CMyGridProperty::OnDrawValue(CDC* pDC, CRect rect)
{
// pre-processing
// ...
CString strVal = FormatProperty();
if(!strVal.IsEmpty())
{
strVal = _T("******"); // NOTE: replace the plain text with "******"
}
rect.DeflateRect(AFX_TEXT_MARGIN, 0);
pDC->DrawText(strVal, rect, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_END_ELLIPSIS);
// post-processing
// ...
}
CWnd* CMyGridProperty::CreateInPlaceEdit(CRect rectEdit, BOOL& bDefaultFormat)
{
// pre-processing
// ...
CEdit* pWndEdit = new CEdit;
DWORD dwStyle = WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL | ES_PASSWORD; // NOTE: add 'ES_PASSWORD' style here
pWndEdit->Create(dwStyle, rectEdit, m_pWndList, AFX_PROPLIST_ID_INPLACE);
// post-processing
// ...
return pWndEdit;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.