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.
Are you only trying to copy the text itself, not the formatted text?
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.
Seems like EM_GETSELTEXT (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditmessages/em_getseltext.asp) might be the message for you.
Example:
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;
Cheers.