Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: Okee on July 26, 2005, 09:36 PM

Title: [Win32] Copying highlighted text from rich edit control and save to string
Post by: Okee on July 26, 2005, 09:36 PM
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.
Title: Re: [Win32] Copying highlighted text from rich edit control and save to string
Post by: MyndFyre on July 26, 2005, 10:07 PM
Are you only trying to copy the text itself, not the formatted text?
Title: Re: [Win32] Copying highlighted text from rich edit control and save to string
Post by: Okee on July 26, 2005, 10:09 PM
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.
Title: Re: [Win32] Copying highlighted text from rich edit control and save to string
Post by: MyndFyre on July 26, 2005, 10:36 PM
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.