0

我有一个项目有一个带密码模式的文本框。但这必须在它有焦点时显示,当它杀死他的焦点时隐藏角色。

这是我的源代码。m_editBox 是 IDC_EDIT1 的控制变量。

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

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

但是 OnEnKillfocusEdit() 不能清楚地工作。我调试了它并检查了进入这个模块。

我该如何解决这个问题。谢谢。

4

1 回答 1

0

我自己做的。我在发送消息后错过了 Invalidate() 函数。我检查了 SetpasswordChar()、SendNotifyMessage、PostMessage() 也可以正常工作。

这是我的代码:

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

谢谢。

于 2013-12-07T19:25:39.967 回答