0

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.

bTagTiger
  • 1,261
  • 5
  • 23
  • 38
  • Not sure why it does not work, try `m_editBox.PostMessage(EM_SETPASSWORDCHAR, (WPARAM) '*', NULL);` – Edward Clements Dec 06 '13 at 08:43
  • Use Spy++ to track where the EM_SETPASSWORDCHAR message is going. this should tell you who is handling it. Additionally, I would try "posting" the message rather than trying to "send" it. – rrirower Dec 06 '13 at 13:59
  • I did it with PostMessage(...), But it also not work. – bTagTiger Dec 06 '13 at 17:52

1 Answers1

0

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.

bTagTiger
  • 1,261
  • 5
  • 23
  • 38