CEdit控件最大长度?(可以显示的字符)
MFC 中 CEdit 控件中包含的文本字符串的最大长度是多少?尝试在字符 30001 之后添加字符时发出哔哔声,这是否记录在任何地方?我可以在 CEdit 中显示更长的文本吗?我应该使用其他控件吗?
What is the maximum length for the text string contained in a CEdit control in MFC? I get a beep when trying to add a character after the character 30001 is this documented anywhere? Can I display longer texts in a CEdit? Should I use another control?
正如Windows 程序员"在下面所说,用户键入时的文本长度限制与我们使用 SetWindowText 以编程方式设置文本时的文本长度限制不同.任何地方都没有提到以编程方式设置文本的限制.用户输入的默认文本长度限制是错误的.(见下面我自己的帖子).
As "Windows programmer" says down below, the text length limit is not the same when the user types as when we programatically set the text using SetWindowText. The limit for setting a text programatically is not mentioned anywhere. The default text lentgth limit for the user typing is wrong. (see my own post below).
我猜在我调用 pEdit->SetLimitText(0) 之后,编程和用户输入文本长度的限制都是 7FFFFFE 字节.我说的对吗?
I'm guessing that after I call pEdit->SetLimitText(0) the limit for both programatically and user input text length is 7FFFFFFE bytes. Am I right?
在 vista 中,将超过 40000 个字符的文本粘贴到 CEdit 中时,它会变得无响应.我之前是否调用过 SetLimitText(100000) 也没关系.
In vista, when pasting text longer than 40000 characters into a CEdit, it becomes unresponsive. It does not matter if I called SetLimitText(100000) previously.
推荐答案
在vista中提到单行CEdit控件的默认大小时发现文档有误.
I found the documentation is wrong when mentioning the default size for a single line CEdit control in vista.
我运行了这段代码:
CWnd* pWnd = dlg.GetDlgItem(nItemId);
CEdit *edit = static_cast<CEdit*>(pWnd); //dynamic_cast does not work
if(edit != 0)
{
UINT limit = edit->GetLimitText(); //The current text limit, in bytes, for this CEdit object.
//value returned: 30000 (0x7530)
edit->SetLimitText(0);
limit = edit->GetLimitText();
//value returned: 2147483646 (0x7FFFFFFE)
}
文档说明:
在调用 EM_SETLIMITTEXT 之前,文本数量的默认限制 a用户可以在编辑控件中输入32,767 个字符.
Before EM_SETLIMITTEXT is called, the default limit for the amount of text a user can enter in an edit control is 32,767 characters.
这显然是错误的.
相关文章