J.Doe
J.Doe

Reputation: 55

How to insert an edit box into CMFCPropertyGridCtrl for password usage?

I want to insert an edit box into CMFCPropertyGridCtrl for inputting password. But the CMFCPropertyGridProperty can only create normal edit box. How can i create a new one for password usage ?

Upvotes: 1

Views: 709

Answers (1)

kissLife
kissLife

Reputation: 327

Derive a new class from CMFCPropertyGridProperty and override two functions: OnDrawValue() and CreateInPlaceEdit().

The code prototype may look like this:

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;
}

Upvotes: 3

Related Questions