CEdit::SetPasswordChar does not work in kill focus event

467 Views Asked by At

I have a project have a textbox with password mode. But this must be show when it has focus and hide characters when it kills his focus.

This is my source code. m_editBox is control variable of IDC_EDIT1.

void CEditBoxTestDlg::OnEnSetfocusEdit1()
{
    //m_editBox.SetPasswordChar(0);
}

void CEditBoxTestDlg::OnEnKillfocusEdit1()
{
    //m_editBox.SetPasswordChar('*');            //1
    m_editBox.SendNotifyMessage(EM_SETPASSWORDCHAR, (WPARAM) '*', NULL);    //2
}

But OnEnKillfocusEdit() does not work clearly. I debugged it and I check enter this module.

How can I slove this problem. Thanks.

1

There are 1 best solutions below

0
On

I did it myself. I missed Invalidate() function after sendmessage. And I checked SetpasswordChar(), SendNotifyMessage, PostMessage() are also work finely.

Here is my code:

void CEditBoxTestDlg::OnEnSetfocusEdit1()
{
    m_editBox.SetPasswordChar(0);
    m_editBox.Invalidate();
}

void CEditBoxTestDlg::OnEnKillfocusEdit1()
{
    //This 3 types also works fine
    //m_editBox.SetPasswordChar('*');
    //m_editBox.SendNotifyMessage(EM_SETPASSWORDCHAR, (WPARAM) '*', NULL);
    m_editBox.PostMessage(EM_SETPASSWORDCHAR, (WPARAM) '*', NULL);

m_editBox.Invalidate();
}

Thanks.