Sending Large Text Buffers to a Rich Edit Control

Started by
1 comment, last by RonHiler 17 years, 8 months ago
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?
Creation is an act of sheer will
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. :)
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.
Creation is an act of sheer will

This topic is closed to new replies.

Advertisement