CEdit控件最大长度? (可以显示的字符)

发布于 2024-07-06 03:41:08 字数 448 浏览 4 评论 0原文

MFC 中 CEdit 控件中包含的文本字符串的最大长度是多少? 当我尝试在字符 30001 之后添加字符时,我听到蜂鸣声,这是否记录在任何地方? 我可以在 CEdit 中显示更长的文本吗? 我应该使用其他控件吗?

正如“Windows 程序员”在下面所说,用户键入时的文本长度限制与我们使用 SetWindowText 以编程方式设置文本时的文本长度限制不同。 任何地方都没有提到以编程方式设置文本的限制。 用户输入的默认文本长度限制是错误的。 (请参阅下面我自己的帖子)。

我猜测在调用 pEdit->SetLimitText(0) 后,编程方式和用户输入文本长度的限制都是 7FFFFFFE 字节。 我对吗?

在 vista 中,当将超过 40000 个字符的文本粘贴到 CEdit 中时,它会变得无响应。 如果我之前调用过 SetLimitText(100000) 也没关系。

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?

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).

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?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光与爱终年不遇 2024-07-13 03:41:08

我发现文档中提到 vista 中单行 CEdit 控件的默认大小时是错误的。

我运行了这段代码:

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 个字符。

这显然是错误的。

I found the documentation is wrong when mentioning the default size for a single line CEdit control in vista.

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.

which is apparently wrong.

呆萌少年 2024-07-13 03:41:08

您可以通过调用 CEdit 来了解您的控件的最大值是多少::GetLimitText() 在您的控件上。 这将返回字符数据的最大大小(以字节为单位)。 您可以使用 CEdit::SetLimitText() 更改最大大小 函数。

SetLimitText() 函数相当于发送 EM_SETLIMITTEXT 消息。 该消息的文档给出了可以使用的最大大小,但由于这些 MSDN 链接可能会在明天被破坏,所以我将复制相关信息:)

UINT 参数解释为:

用户TCHAR的最大数量
可以进入。 对于 ANSI 文本,这是
字节数; 对于 Unicode 文本,
这是字符数。 这
数量不包括
终止空字符。 丰富的编辑
控制:如果该参数为零,
文本长度设置为 64,000
字符。

在 Windows NT/2000/XP 上编辑控件:
如果此参数为零,则文本
长度设置为 0x7FFFFFFE 个字符
对于单行编辑控件或 –1
用于多行编辑控件。

在 Windows 95/98/Me 上编辑控件:如果
该参数为零,文本
长度设置为 0x7FFE 字符
单行编辑控件或 0xFFFF
用于多行编辑控件。

另外,从备注部分:

在调用 EM_SETLIMITTEXT 之前,
文本量的默认限制 a
用户可以在编辑控件中输入的是
32,767 个字符。

在 Windows NT/2000/XP 上编辑控件:
对于单行编辑控件,
文本限制为 0x7FFFFFFE 字节
或 wParam 参数的值,
以较小者为准。 对于多线
编辑控件,该值为 –1
字节或 wParam 的值
参数,以较小者为准。

在 Windows 95/98/Me 上编辑控件:对于
单行编辑控件,文本
限制是 0x7FFE 字节或
wParam 参数的值,
以较小者为准。 对于多线
编辑控件,该值是
0xFFFF 字节或值
wParam参数,取其中的
更小。

我认为他们的意思是 0xFFFFFFFF 而不是第二段中的 -1 ......

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.

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 :)

The UINT parameter is interpreted as:

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.

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.

I assume they meant 0xFFFFFFFF instead of -1 in the second paragraph there...

憧憬巴黎街头的黎明 2024-07-13 03:41:08

“(可以显示的字符)” != “尝试添加字符时”。

"尝试添加字符时" == "用户可以输入的最大 TCHAR 数"
除非您的意思是以编程方式尝试添加字符。

"0x7FFFFFFE 字符" != "0x7FFFFFFE 字节"
除了有时,引用的 MSDN 文本有时可以理解这一事实。

我敢打赌没有人知道最初问题的答案。 但“0x7FFFFFFE 字节”可能是众多限制之一。

"(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.

"0x7FFFFFFE characters" != "0x7FFFFFFE bytes"
except sometimes, a fact which the quoted MSDN text understands sometimes.

I'll bet no one knows the answer to the original question. But "0x7FFFFFFE bytes" is likely one of many limits.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文