我正在生成一个自定义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());
}发布于 2020-03-13 18:46:24
我正在查找CEdit::GetPasswordChar,我注意到上面写着:
如果使用
ES_PASSWORD样式创建编辑控件,则使用(支持该控件的DLL )确定默认密码字符。清单或InitCommonControlsEx方法确定哪个DLL支持编辑控件。如果user32.dll支持编辑控件,则默认密码字符为星号('*',U+002A)。如果comctl32.dll版本6支持编辑控件,默认字符是黑圈(‘’,U+25CF)。有关哪个DLL和版本支持通用控件的详细信息,请参阅Shell and Common Controls Versions。
尽管如此,为什么不直接使用CEdit::SetPasswordChar来说明:
指定要显示的字符,以代替用户键入的字符。如果ch为0,则显示用户键入的实际字符。
。
https://stackoverflow.com/questions/60667554
复制相似问题