Re: Converting text to Rich Text Format

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Add the string. Set its style.

There is one little glitch in setting the selection which I discovered last night (since
I'm currently using a rich edit control to display some text). If you do

int length = c_Text.GetLength();
c_Text.SetSel(length, length);

int line = c_Text.LineFromChar(length); // see discussion below

c_Text.ReplaceSel(length);
CHARFORMAT2 fmt;
fmt.dwMask = CFE_COLOR;
fmt.crTextColor = ...;

int end = c_Text.GetLength();
c_Text.SetSel(length - line, end - line);
c_Text.SetSelectionCharFormat(fmt);

There is a "creep" where the SetSelection selects the wrong text depending on how many
lines precede the text. No, I don't know what is wrong here, and there appears to be no
documentation about the problem, but I noticed that the colors were slowly moving to the
right.

I'm not sure this will work correctly in the presence of line wrap, but all my output fits
on one line at the moment.
joe

On Fri, 8 Sep 2006 09:49:23 -0500, "Peter Olcott" <NoSpam@xxxxxxxxxxxxx> wrote:

Could you describe the process of converting text to Rich Text using the Rich
Edit Control, given an array of strings each with corresponding LOGFONT and
(foreground color)COLORREFs?

These are the only formatting aspects that I need to retain, I do not need any
paragraph formatting attributes such as left/right/center justification.


"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:t8v2g21h8845bkf2jnknqkrtdiemaolgk6@xxxxxxxxxx
CRichEdit::SetSel
joe

On Thu, 7 Sep 2006 23:24:58 -0500, "Peter Olcott" <NoSpam@xxxxxxxxxxxxx>
wrote:

I could drop the text into a Rich Edit Control, and then the user could
cut-and-paste it to anywhere they want. What I don't get about this is how you
make a text selection in a Rich Edit Control, programmatically.

"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:idq1g21fgr4lmotft494h6qsfihte7qfpd@xxxxxxxxxx
You can use SetSelectionCharFormat in the rich edit control, or use the
StreamIn to read
encoded RTF. It's up to you which makes sense in your application. Note
the
rtf doesn't
have to be in a file, because StreamIn doesn't care how you deliver the
text.
joe

On Thu, 7 Sep 2006 15:38:23 -0500, "Peter Olcott" <NoSpam@xxxxxxxxxxxxx>
wrote:

I was hoping that there was a short-cut to this method by using the Rich
Edit
Control.

"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:v5u0g2d40nq4tam0tsl8vpv04agmpkh7km@xxxxxxxxxx
You have to read about the Rich Text Format syntax. Or a simple way,
format
the text you
want in WordPad and write it out, then look at what got written and
replicate
it.
joe

On Thu, 7 Sep 2006 13:30:32 -0500, "Peter Olcott" <NoSpam@xxxxxxxxxxxxx>
wrote:

If I start with a set of text strings where each text string is associated
with
a LOGFONT and COLORREF (for its foreground color), how do I convert this
to
Rich
Text Format?

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Converting text to Rich Text Format
    ... There is one little glitch in setting the selection which I discovered last ... These are the only formatting aspects that I need to retain, ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: SetSelectionCharFormat specific failure....
    ... But my observation is that "dwEffects must be set even for color ... formatting" which is not expected as per docs. ... class, from dialog, which holds this rich edit. ... MVP Tips:http://www.flounder.com/mvp_tips.htm-Hide quoted text - ...
    (microsoft.public.vc.mfc)
  • Re: SetSelectionCharFormat specific failure....
    ... Rich Edit 2.1 in MFC ... SetSelectionCharFormatfails in my case, when I pass off handle to ... but this formatting does not work. ... I debugged to SendMessage() call within above routine, ...
    (microsoft.public.vc.mfc)
  • Re: Highlighted text in RichEditCtrl
    ... You must also use the rich edit 2.0 or better control. ... bypass the MFC rich edit functions, and send messages (i.e., the ...
    (microsoft.public.vc.mfc)
  • Re: Subclass a CRichEditCtrl, having trouble overriding OnNotify()
    ... the rich edit control. ... as a child of your rich edit, you won't see any WM_NOTIFY messages in your subclass. ... parent; if you return TRUE, ...
    (microsoft.public.vc.mfc)