CEdit control maximum length? (in characters it can display)

坚强是说给别人听的谎言 提交于 2019-11-29 06:43:38

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.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!