Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MFC Rich Edit Control

165 views
Skip to first unread message

Scott Kraemer

unread,
Jul 30, 2007, 2:07:19 PM7/30/07
to
I'm a newb at programming, but I can usualy peice stuff together that I
find.
I am useing the Rich Edit Control. I am making a chat control, where I
want
multi-color, bold, etc different on each line, or even perhaps multi colored
line.

I have extended it to getRTF, setRTF and to AppendText to find that I have
to get/set in the whole document everytime I want to edit the document.

Is there a way I can add formating to strings in real time? The Append Text
works fine. I just want to add color.

For example:

SetColor(<color i want>)
AppendText("Joined Chat")
SetColor(<new color>);
SetBold()
AppendText("QUIT chat")


AliR (VC++ MVP)

unread,
Jul 30, 2007, 2:34:09 PM7/30/07
to
Have you tried EM_SETTEXTEX. If you have the text you want to insert in RTF
format you can use this to append it to the rich edit control.

Otherwise if you simply want to change the color of the text then keep track
of the last index of the text in the edit control before you insert your
text, then after you insert the text call SetSel
(SetSel(Index,Index+LengthIJustAdded)) and then change the formating as
usual using SetSelectionCharFormat or EM_SETCHARFORMAT.


AliR.

"Scott Kraemer" <skra...@cox.net> wrote in message
news:uHdd7Rt0...@TK2MSFTNGP02.phx.gbl...

Scott Kraemer

unread,
Jul 30, 2007, 3:55:08 PM7/30/07
to
do you mean something like this? It didnt work...

SETTEXTEX setTextEx;
setTextEx.codepage=1250;
setTextEx.flags=ST_DEFAULT;

CChatRichEd *caption=(CChatRichEd*)GetDlgItem(IDC_CHAT);
if(caption!=NULL)
caption->SendMessage(EM_SETTEXTEX, (WPARAM)&setTextEx, (LPARAM)"This is a
test \b BOLD \b0 ");


"AliR (VC++ MVP)" <Al...@online.nospam> wrote in message
news:Baqri.46404$YL5....@newssvr29.news.prodigy.net...

AliR (VC++ MVP)

unread,
Jul 30, 2007, 4:23:21 PM7/30/07
to
Here is a sample that I tested. m_Source and m_Dest are both CAutoRichEdit
controls. (It make life eaiser)
http://www.codeproject.com/richedit/autoricheditctrl.asp

CString RTF = m_Source.GetRTF();

SETTEXTEX SetTextEx;
SetTextEx.codepage = 1200;
SetTextEx.flags = ST_SELECTION;

m_Dest.SetSel(-1,-1);
m_Dest.SendMessage(EM_SETTEXTEX,(WPARAM)&SetTextEx,(LPARAM)RTF.GetBuffer());
RTF.ReleaseBuffer();


you can download the sample from here (VS2003). the bottom edit control is
where you type, you can change the text to bold and italic and change its
color, press send and it will get appended to the end of the top edit
control, and keeps the exact formating. (just like a chat window)

http://www.learnstar.com/AliR/AppendRTF.zip

AliR.

"Scott Kraemer" <skra...@cox.net> wrote in message

news:uQNVMOu0...@TK2MSFTNGP02.phx.gbl...

Scott Kraemer

unread,
Jul 30, 2007, 5:14:43 PM7/30/07
to
I figured it out... I wasnt sending the full RTF prefix + CString + postfix

So I am working now :) thanks!


"AliR (VC++ MVP)" <Al...@online.nospam> wrote in message
news:Baqri.46404$YL5....@newssvr29.news.prodigy.net...

0 new messages