Jump to content
  • Advertisement
Sign in to follow this  
RonHiler

Sending Large Text Buffers to a Rich Edit Control

This topic is 4305 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I've been working with several Rich Edit controls lately. Things were going just fine while the amount of text I was sending was relatively short, but then I hit a snag when my text size got larger than 4K. This is my calling routine and the callback function.

//---------------------------------------------------------------------------
void ForumExportClass::FillExampleExportBox()
    {
    EDITSTREAM Stream;
    string Description;
    string rtfPrefix = "{\\rtf1\\ansi\\deff0\\deftab720{\\fonttbl{\\f0\\froman "
		"Courier;}}\n{\\colortbl\\red255\\green255\\blue255;\\red230 \\green230\\blue0;"
        "\\red100\\green100\\blue255;}\n"
	"\\deflang1033\\pard\\plain\\f3\\fs22\\cf0 ";
    string rtfPostfix = "\n\\par }";

    Description.reserve(32768);

    Description = rtfPrefix;
    Description += FillExampleExportBoxHeader();
    Description += FillExampleExportBoxTitle();
    Description += FillExampleExportBoxAbilities();
    Description += FillExampleExportBoxSkills();
    Description += FillExampleExportBoxLevelBreakdown();
    Description += rtfPostfix;

    Stream.dwCookie = (DWORD)&Description;
    Stream.dwError = false;
    Stream.pfnCallback = ExportExampleStreamCallback;
    SendMessage(ExampleOutputBox, EM_STREAMIN, SF_RTF, (LPARAM)&Stream);
    }

//---------------------------------------------------------------------------
DWORD CALLBACK ExportExampleStreamCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG FAR *pcb)
    {
    string text = *(string*)dwCookie;

    //String smaller than buffer
    if( text.length() < cb )
        {
	*pcb = text.length();
	memcpy(pbBuff,text.c_str(),*pcb);
	}
    //String larger than buffer
    else
        {
	*pcb = cb;
	memcpy(pbBuff,text.c_str(),*pcb);
	text.erase(0,*pcb-1);
	}
    return 0;
    }

This function works fine as long as text.length() < cb (which is 4K). However, the other case does not work. What happens is the string is printed to the control up to 4K worth of text, but then when it comes back to print the rest, the string is not modified, it just reprints the first 4K again. It does this over and over until the control hits it's max text limit (32K I believe). I've tried various permutations of this, but I simply cannot get it to work :) Anyone see what I'm doing wrong here?

Share this post


Link to post
Share on other sites
Advertisement
A guess out-my-ass.

Change:
 string text = *(string*)dwCookie;

to
 string& text = *(string*)dwCookie;


This is based off the fact that you seem to think changing the contents of "text" will do something, not off of any understanding of RTF controls. :)

Share this post


Link to post
Share on other sites
You totally nailed it, NotAYakk. Thank you so much! I was going crazy trying to figure out what was wrong with the control and it wasn't the control at all, heh. I HATE when I drop an ampersand, those are the worst bugs to find.

Thanks, you've saved my sanity. I can continue on with more productive work now.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!