【问题标题】:Unicode character into CEditUnicode 字符到 CEdit
【发布时间】:2020-06-25 07:08:53
【问题描述】:

我正在生成一个自定义CEdit 控件,允许我在其上设置一些不同的颜色。在我使用 ES_PASSWORD 样式生成控件之前,它工作正常。

在这些情况下,我找不到写我想要的字符(大黑点)的方法。以下是我尝试过的一些代码:

第一个选项:

int lenght = text.GetLength();
text = "";
for (int i = 0; i < lenght; i++) text.AppendChar('\u25CF');

第二个选项:

int lenght = text.GetLength();
text = "";
for (int i = 0; i < lenght; i++) text.Append("\u25CF");

第三个选项:

int lenght = text.GetLength();
text = "";
for (int i = 0; i < lenght; i++) text.AppendChar((char)"\u25CF");

我不明白为什么控件不显示正确的字符。它只显示这个:&lt;。我究竟做错了什么?

更新

这是我正在使用的OnPaint() 方法:

void CEasyEdit::OnPaint()
{
    // I generate all requiered objects.
    CPaintDC dc(this);
    CRect ClientRect;
    GetClientRect(&ClientRect);

    // I define which colors I want to use.
    SetDefaultColors();

    // I paint the background and its borders.
    CBrush brush(m_clrBack);
    dc.FillRect(ClientRect, &brush);
    CRect border_rect;
    this->GetClientRect(border_rect);
    border_rect.InflateRect(1, 1);
    dc.Draw3dRect(border_rect, m_clrBack, m_clrBack);
    border_rect.InflateRect(1, 1);
    dc.Draw3dRect(border_rect, m_clrBack, m_clrBack);

    // I redefine the size of the rect.
    CRect textRect(ClientRect);
    textRect.DeflateRect(4, 1);

    // I define the text to draw.
    CString text;
    GetWindowText(text);

    // If it displays a password, I change its characters.
    if (GetStyle() & ES_PASSWORD)
    {
        // I redefine the text to show.
        int lenght = text.GetLength();
        wchar_t f = '1060';
        text = "";
        for (int i = 0; i < lenght; i++) text.Append("\u0053");
    }

    // I draw the text.
    dc.SetTextColor(m_clrText);
    dc.SetBkColor(m_clrBack);   
    dc.SelectObject(GetFont());
    dc.DrawText(text, -1, textRect, GetStyle());
}

【问题讨论】:

标签: c++ unicode mfc


【解决方案1】:

我正在查找 CEdit::GetPasswordChar,我注意到它说:

如果您使用ES_PASSWORD 样式创建编辑控件,DLL 支持控件确定默认密码字符。 清单或 InitCommonControlsEx 方法确定哪个 DLL 支持编辑控件。如果 user32.dll 支持编辑控件, 默认密码字符是 ASTERISK ('*', U+002A)。 如果 comctl32.dll 6版支持编辑控件,默认 字符是黑圈('●',U+25CF)。有关更多信息 哪些DLL和版本支持常用控件,请参见Shell and Common Controls Versions

也就是说,你为什么不能在它声明的地方使用CEdit::SetPasswordChar

指定要显示的字符代替字符 由用户键入。如果 ch 为 0,则用户输入的实际字符 显示出来。

【讨论】:

  • 对于 ANSI 程序,会显示 '*' 或其他一些 ANSI 字符。 ANSI 程序可以用::SendMessageW(edit-&gt;m_hWnd, EM_SETPASSWORDCHAR, L'●', 0); 打补丁 关于InitCommonControlsEx 的注释可能已经过时了。
猜你喜欢
  • 2017-11-19
  • 2013-10-17
  • 1970-01-01
  • 2011-04-02
  • 2012-05-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多