Valhalla Legends Forums Archive | C/C++ Programming | [Win32] Copying highlighted text from rich edit control and save to string

AuthorMessageTime
Okee
Hey guys, I'm trying to copy the highlighted text from a rich edit control and save it into a string so I can eventually spit it back out later. I've been looking into EM_EXGETSEL, but I don't see where it explains how to use that to actually copy the text into a string. Seems like all it does is copy information about the selection.

My question is how do I go about saving the highlighted text so I can print it out later? I want to copy it into a character array.

Thanks in advance.
July 27, 2005, 2:36 AM
Myndfyr
Are you only trying to copy the text itself, not the formatted text?
July 27, 2005, 3:07 AM
Okee
Strictly the text. I'm going to append the text to the end of a text file. No formatting required as far as I assumed.
July 27, 2005, 3:09 AM
Myndfyr
Seems like EM_GETSELTEXT might be the message for you.

Example:

[code]
CHARRANGE range;
SendMessage(hRtfBox, EM_EXGETSEL, NULL, &range);
LONG length = range.cpMax - range.cpMin;
char *buffer = new char[length + 1];
if (!buffer)
  return 0;
lResult = SendMessage(hRtfBox, EM_GETSELTEXT, NULL, (LPARAM)buffer);
if (lResult != length)
  return lResult;

// here is where you do whatever it is you're going to do.  text is in the buffer variable.

delete[] buffer;
[/code]

Cheers.
July 27, 2005, 3:36 AM

Search