gpt4 book ai didi

c++ - Unicode字符转换为CEdit

转载 作者:行者123 更新时间:2023-12-02 10:04:58 27 4
gpt4 key购买 nike

我正在生成一个自定义的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");

我不明白为什么控件没有显示正确的字符。它仅显示以下内容: <。我究竟做错了什么?

更新

这是我正在使用的 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());
}

最佳答案

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

If you create the edit control with the ES_PASSWORD style, the DLL that supports the control determines the default password character. The manifest or the InitCommonControlsEx method determines which DLL supports the edit control. If user32.dll supports the edit control, the default password character is ASTERISK ('*', U+002A). If comctl32.dll version 6 supports the edit control, the default character is BLACK CIRCLE ('●', U+25CF). For more information about which DLL and version supports the common controls, see Shell and Common Controls Versions.



就是说,为什么不能只使用 CEdit::SetPasswordChar 声明:

Specifies the character to be displayed in place of the character typed by the user. If ch is 0, the actual characters typed by the user are displayed.

关于c++ - Unicode字符转换为CEdit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60667554/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com