string CEdit控件最大长度?(以可以显示的字符为单位)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/180853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CEdit control maximum length? (in characters it can display)
提问by rec
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?
MFC 中 CEdit 控件中包含的文本字符串的最大长度是多少?在字符 30001 是否记录在任何地方之后尝试添加字符时,我会听到蜂鸣声?我可以在 CEdit 中显示更长的文本吗?我应该使用另一个控件吗?
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).
正如下面的“Windows 程序员”所说,用户键入时的文本长度限制与我们使用 SetWindowText 以编程方式设置文本时的文本长度限制不同。任何地方都没有提到以编程方式设置文本的限制。用户输入的默认文本长度限制是错误的。(见下面我自己的帖子)。
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?
我猜在我调用 pEdit->SetLimitText(0) 之后,以编程方式和用户输入文本长度的限制是 7FFFFFFE 字节。我对吗?
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 中,将超过 40000 个字符的文本粘贴到 CEdit 中时,它变得无响应。我之前是否调用过 SetLimitText(100000) 并不重要。
回答by rec
I found the documentation is wrong when mentioning the default size for a single line CEdit control in vista.
在 vista 中提到单行 CEdit 控件的默认大小时,我发现文档是错误的。
I ran this code:
我运行了这个代码:
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)
}
the documentation states:
该文件指出:
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.
在调用 EM_SETLIMITTEXT 之前,用户可以在编辑控件中输入的文本量的默认限制是 32,767 个字符。
which is apparently wrong.
这显然是错误的。
回答by ryan_s
You can find out what the maximum is for your control by calling CEdit::GetLimitText()on your control. This returns the maximum size for character data in bytes. You can change the maximum size using the CEdit::SetLimitText()function.
您可以通过在控件上调用CEdit::GetLimitText()来找出控件的最大值。这将返回字符数据的最大大小(以字节为单位)。您可以使用CEdit::SetLimitText()函数更改最大大小。
The SetLimitText() function is equivalent to sending an EM_SETLIMITTEXTmessage. The documentation for that message gives the maximum sizes that can be used, but since these are MSDN links that will probably be broken by tomorrow, I'll copy the relevant information :)
SetLimitText() 函数相当于发送一个EM_SETLIMITTEXT消息。该消息的文档给出了可以使用的最大大小,但由于这些是 MSDN 链接,明天可能会被破坏,我将复制相关信息:)
The UINT parameter is interpreted as:
UINT 参数解释为:
The maximum number of TCHARs the user can enter. For ANSI text, this is the number of bytes; for Unicode text, this is the number of characters. This number does not include the terminating null character. Rich edit controls: If this parameter is zero, the text length is set to 64,000 characters.
Edit controls on Windows NT/2000/XP: If this parameter is zero, the text length is set to 0x7FFFFFFE characters for single-line edit controls or –1 for multiline edit controls.
Edit controls on Windows 95/98/Me: If this parameter is zero, the text length is set to 0x7FFE characters for single-line edit controls or 0xFFFF for multiline edit controls.
用户可以输入的最大 TCHAR 数。对于 ANSI 文本,这是字节数;对于 Unicode 文本,这是字符数。此数字不包括终止空字符。丰富的编辑控件:如果此参数为零,则文本长度设置为 64,000 个字符。
Windows NT/2000/XP 上的编辑控件:如果此参数为零,则文本长度设置为 0x7FFFFFFE 字符(用于单行编辑控件)或 –1 用于多行编辑控件。
Windows 95/98/Me 上的编辑控件:如果此参数为零,则文本长度设置为 0x7FFE 字符用于单行编辑控件或 0xFFFF 用于多行编辑控件。
Also, from the Remarks section:
另外,从备注部分:
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.
Edit controls on Windows NT/2000/XP: For single-line edit controls, the text limit is either 0x7FFFFFFE bytes or the value of the wParam parameter, whichever is smaller. For multiline edit controls, this value is either –1 bytes or the value of the wParam parameter, whichever is smaller.
Edit controls on Windows 95/98/Me: For single-line edit controls, the text limit is either 0x7FFE bytes or the value of the wParam parameter, whichever is smaller. For multiline edit controls, this value is either 0xFFFF bytes or the value of the wParam parameter, whichever is smaller.
在调用 EM_SETLIMITTEXT 之前,用户可以在编辑控件中输入的文本量的默认限制是 32,767 个字符。
Windows NT/2000/XP 上的编辑控件:对于单行编辑控件,文本限制为 0x7FFFFFFE 字节或 wParam 参数的值,以较小者为准。对于多行编辑控件,此值为 –1 字节或 wParam 参数的值,以较小者为准。
Windows 95/98/Me 上的编辑控件:对于单行编辑控件,文本限制为 0x7FFE 字节或 wParam 参数的值,以较小者为准。对于多行编辑控件,此值是 0xFFFF 字节或 wParam 参数的值,以较小者为准。
I assume they meant 0xFFFFFFFF instead of -1 in the second paragraph there...
我认为他们的意思是 0xFFFFFFFF 而不是第二段中的 -1 ......
回答by Windows programmer
"(in characters it can display)" != "when trying to add a character".
"(以它可以显示的字符为单位)" != "当试图添加一个字符时"。
"when trying to add a character" == "The maximum number of TCHARs the user can enter" unless you mean programmatically trying to add a character.
“尝试添加字符时”==“用户可以输入的最大 TCHAR 数”,除非您的意思是以编程方式尝试添加字符。
"0x7FFFFFFE characters" != "0x7FFFFFFE bytes" except sometimes, a fact which the quoted MSDN text understands sometimes.
"0x7FFFFFFE characters" != "0x7FFFFFFE bytes" 有时除外,引用的 MSDN 文本有时会理解这一事实。
I'll bet no one knows the answer to the original question. But "0x7FFFFFFE bytes" is likely one of many limits.
我敢打赌没有人知道原始问题的答案。但“0x7FFFFFFE 字节”可能是众多限制之一。