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以编程方式设置文本时不一样。在任何地方都没有提到以编程方式设置文本的限制。用户输入的默认文本lentgth限制是错误的。 (见下面我自己的帖子)。
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)并不重要。
3 个解决方案
#1
13
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.
这显然是错的。
#2
6
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_SETLIMITTEXT message. 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.
用户可以输入的最大TCHAR数。对于ANSI文本,这是字节数;对于Unicode文本,这是字符数。此数字不包括终止空字符。丰富的编辑控件:如果此参数为零,则文本长度设置为64,000个字符。
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.
编辑Windows NT / 2000 / XP上的控件:如果此参数为零,则单行编辑控件的文本长度设置为0x7FFFFFFE,多行编辑控件的文本长度设置为-1。
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.
编辑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.
在调用EM_SETLIMITTEXT之前,用户可以在编辑控件中输入的文本量的默认限制为32,767个字符。
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.
编辑Windows NT / 2000 / XP上的控件:对于单行编辑控件,文本限制为0x7FFFFFFE字节或wParam参数的值,以较小者为准。对于多行编辑控件,此值为-1个字节或wParam参数的值,以较小者为准。
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.
编辑Windows 95/98 / Me上的控件:对于单行编辑控件,文本限制为0x7FFE字节或wParam参数的值,以较小者为准。对于多行编辑控件,此值为0xFFFF字节或wParam参数的值,以较小者为准。
I assume they meant 0xFFFFFFFF instead of -1 in the second paragraph there...
我假设它们的意思是0xFFFFFFFF而不是第二段中的-1 ......
#3
2
"(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字节”可能是许多限制之一。
#1
13
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.
这显然是错的。
#2
6
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_SETLIMITTEXT message. 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.
用户可以输入的最大TCHAR数。对于ANSI文本,这是字节数;对于Unicode文本,这是字符数。此数字不包括终止空字符。丰富的编辑控件:如果此参数为零,则文本长度设置为64,000个字符。
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.
编辑Windows NT / 2000 / XP上的控件:如果此参数为零,则单行编辑控件的文本长度设置为0x7FFFFFFE,多行编辑控件的文本长度设置为-1。
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.
编辑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.
在调用EM_SETLIMITTEXT之前,用户可以在编辑控件中输入的文本量的默认限制为32,767个字符。
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.
编辑Windows NT / 2000 / XP上的控件:对于单行编辑控件,文本限制为0x7FFFFFFE字节或wParam参数的值,以较小者为准。对于多行编辑控件,此值为-1个字节或wParam参数的值,以较小者为准。
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.
编辑Windows 95/98 / Me上的控件:对于单行编辑控件,文本限制为0x7FFE字节或wParam参数的值,以较小者为准。对于多行编辑控件,此值为0xFFFF字节或wParam参数的值,以较小者为准。
I assume they meant 0xFFFFFFFF instead of -1 in the second paragraph there...
我假设它们的意思是0xFFFFFFFF而不是第二段中的-1 ......
#3
2
"(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字节”可能是许多限制之一。