Rich edit (CRichEditCtrl) & SetWindowText

I've got a rich edit control that I'm trying to set to a CString.  Actually, I've got it to work, except that the string itself can only hold as many characters as initially available.  Here's the code from my view with the CRichEdit:

CFtpDoc* pDoc = (CFtpDoc*)GetDocument();

I can delete & change text, but say if I had 300 characters and deleted 5, I'd be able to add only 5 characters back in the editor.

Can anyone help?
Who is Participating?
captainkirkConnect With a Mentor Commented:
if you define the buffer like this:

char* buffer = new char(MAXBUFFER);

then you can make the buffer grow by doing something like:

buffer = (char*)realloc(buffer, MAXBUFFER + SOME_INCREMENT);

where SOME_INCREMENT is defined to whatever value you want; you could even use a variable there, or whatever. This way you are not stuck with the buffer limit you previously imposed.

I noticed that you are only reading in MAXBUFFER bytes at a time from your file and setting the control's text to just what is in the buffer. You might want to add code to append to the content of the control if necessary.
if I understand you right, you mean to say that the CString or LPCSTR you are assigning the text to will not grow?? If that is the case, perhaps you need to reallocate the memory yourself...
knewton76Author Commented:
It doesn't grow.  How would I reallocate the memory myself?  (I'm a newbie, can you tell?)

Here's how I do the data gathering:

char buffer[MAXBUFFER]

int nread = pFile->Read(buffer, MAXBUFFER);

So, the text comes in from a file to a char buffer, then I do something like this:

in the Document, SetEditData looks like this:

void SetEditData(char*buffer)
  m_strText = buffer;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.