【发布时间】: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");
我不明白为什么控件不显示正确的字符。它只显示这个:<。我究竟做错了什么?
更新
这是我正在使用的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());
}
【问题讨论】:
-
CString没有告诉我们相关信息。是CStringA还是CStringW? -
我怎么知道?
-
通过查看您的项目设置和/或构建命令行。或者将鼠标光标悬停在
CString符号上。 Unicode and Multibyte Character Set (MBCS) Support 解释基本原理。