Date: | January 11, 2007 / year-entry #11 |
Tags: | code |
Orig Link: | https://blogs.msdn.microsoft.com/oldnewthing/20070111-02/?p=28443 |
Comments: | 10 |
Summary: | Last time we looked at loading an entire file into a rich text control. The code runs great, until you try to use it to display a license agreement provided by your legal department, and then some paranoid user reports that they can't read past page seven. (What, somebody reads those things?) What's going on?... |
Last time we looked at loading an entire file into a rich text control. The code runs great, until you try to use it to display a license agreement provided by your legal department, and then some paranoid user reports that they can't read past page seven. (What, somebody reads those things?) What's going on?
If you don't specify otherwise,
the maximum number of characters in a
rich edit control is 32,767 charaters.
(This limit exists for compatibility with the original rich edit control.)
You can raise the limit with the SendMessage(hwnd, EM_EXLIMITTEXT, 0, -1);
into the program before it calls
Next time, the mystery of rich edit printing. |
Comments (10)
Comments are closed. |
How about the mystery of why one crams the 8pt software licencing agreement into a 40-column-wide rich text control that shows 5 lines per "page"?
As Raymond says, "What, somebody reads those things?"
Mikeb,
Yes, people really do read those things.
Mr. Chen,
Your book arrived at my house yesterday. Thank you once again for all your hard work.
JamesNT
Just out of interest, how does a program end up relying on the 32767 character limit?
Stu: I’d guess by reading the text into a fixed-size 32767 character buffer to manipulate or save it in some way. It knew that it was a big enough buffer due to the control’s character limit.
Just a wild guess, but I suspect I’m in the right ballpark.
I think Raymond’s intention with the sarcastic remark (certainly it would have been my intention) is that the people who write/display those things don’t expect (probably don’t even want) people to read them.
It’s what is sometimes known as ‘fine print’ (http://en.wikipedia.org/wiki/Small_print).
As Raymond might say, "I can’t believe I had to explain that."
I’ve programmed the RichEdit control in assembly (several years ago). Quite a useful thing. Except that why does it display rich text even though it has been set to display plain text?
As an example, type some stuff in Word and give it some fancy formatting (bold, different fonts, etc), and then paste it into a new Outlook Express message (set to Plain Text under the Format menu, not HTML format). Surprise! Can anyone get a RichEdit control not do this?
MSDN for EM_EXLIMITTEXT says that if you pass lParam=0, "the default maximum is used, which is 64K characters".
MFC’s CRichEditView source has the following:
// richedit buffer limit — let’s set it at 16M
AFX_DATADEF ULONG CRichEditView::lMaxSize = 0xffffff;
(BTW, I suppose the "buffer limit" is incorrect — it is the number of TCHARs?)
Is there real upper limit? Is it (~(LPARAM)0)? Can it be set to "unlimited" somehow?
> If you don’t specify otherwise, the maximum
> number of characters in a rich edit control
> is 32,767 charaters.
MSDN partly disagrees with you.
* The EM_EXLIMITTEXT message sets an upper
* limit to the amount of text the user can
* type or paste into a rich edit control.
On some other MSDN page which I can’t find now, I had read that this one really means what it says: the limit affects the user’s typing but does not affect what the program can put into the control.
But on that other MSDN page, I don’t recall reading anything about the way that this page continues, where it partly agrees with you:
* The text limit set by the EM_EXLIMITTEXT
* message does not limit the amount of text
* that you can stream into a rich edit control
* using the EM_STREAMIN message with lParam set
* to SF_TEXT. However, it does limit the amount
* of text that you can stream into a rich edit
* control using the EM_STREAMIN message with
* lParam set to SF_RTF.
Well … assuming that this is among the 75% of MSDN pages that are accurate, it’s no fun but at least it is better to be documented than not to be documented.
I expect it depends on the version of MSDN you are reading. My copy came with VS6 and it says 32K in there. Whether that 32 (or 64) K is bytes or characters I don’t know.
My copy of MSDN also says "The text limit set by the EM_EXLIMITTEXT message does not limit the amount of text that you can stream into a rich edit control using the EM_STREAMIN message." Huh? If it doesn’t limit it how can you raise the limit with it?