How do I put more than 32,000 characters into a rich text control?

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 EM_EXLIMITTEXT message. Therefore, we need to slip the line

SendMessage(hwnd, EM_EXLIMITTEXT, 0, -1);

into the program before it calls FillRichEditFromStream.

Next time, the mystery of rich edit printing.


Comments (10)
  1. Nicholas says:

    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"?

  2. mikeb says:

    >  How about the mystery of why one crams the 8pt software licencing agreement into a 40-column-wide…  <<

    As Raymond says, "What, somebody reads those things?"

  3. JamesNT says:

    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

  4. Stu says:

    Just out of interest, how does a program end up relying on the 32767 character limit?

  5. pcooper says:

    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.

  6. mikeb says:

    > Yes, people really do read those things. <<

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

  7. cm says:

    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?

  8. MD says:

    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?

  9. Norman Diamond says:

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

  10. required says:

    MSDN for EM_EXLIMITTEXT says that if you pass lParam=0, "the default maximum is used, which is 64K characters".

    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?

Comments are closed.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index