Advanced RichEditCtrl

There are two main classes
CRTFBuilder responsible for all RTF building
CRichEditCtrlEx, which simply derives from CRichEditCtrl and adds a few methods

RTFBuilder starts off with 1 font and 4 colors:



black, red, blue, green turns text to the specified color
color Takes a COLORREF and turns the text that color
font Changes the font. Takes a font name as a string
size Takes an integer as the font size
bold(bool) Turns text bold
italic(bool) italic
underline(bool) underline
strike(bool) strike through
normal turns off the above 4 settings
push pushes the current settings on it's own stack
pull pulls the last settings from the stack
write Takes a CRichEditCtrl as a parameter and writes to that control. Can also use the '>>' operator (see example)

RichEditCtrlEx simply derives fron CRichEditCtrl and adds a few methods

It also overrides PreSubclassWindow to turn the background color to that of the dialog(button) color to give the appearance of a simple lable and sets the control to read only.

The export declarations in the 'RichEd' header make it possible to compile RichEditCtrlEx.cpp in either a library of MFC extension DLL.

The 'RichEd' project is the library and the 'test' project is an example dialog based exe project.
To get going, simply compile and run.

Download demo project/source - 21 KB

Date Posted: 08.08.98


  • How can you use this class in a DOC/VIEW

    Posted by Legacy on 08/20/2003 12:00am

    Originally posted by: Tom Hill

    I Already Use in Doc/View by do following:
    I Creat my project with name CTestRichView which inherit from CviewEditCtrl you should see in step 6 of MFC widzard
    Then int function CTestRichViewView::OnInitialUpdate()
    you should insert:
    CRichEditCtrl &theRich=this->GetRichEditCtrl();
    CRTFBuilder b ;
    b << size ( 35 )
    << bold(true)
    << color( 1 )
    << "The Title\n"
    << write( theRich ) ;

    You remember include RichEditCtrlEx.h and Link file Lib
    Hope you success

  • Nice RichText Programming!

    Posted by Legacy on 04/23/2003 12:00am

    Originally posted by: Laser Park

    Thank you!
    Apply my job!

  • [Re] VC6 errors

    Posted by Legacy on 03/07/2003 12:00am

    Originally posted by: Young Su, Cha

    try to do like this;

    for(iterator i=begin(); i!=end(); i++)
    -> for(const_iterator i = begin( ) ; i!=end( ) ; i++)


  • compiler error in VC6

    Posted by Legacy on 09/21/2002 12:00am

    Originally posted by: tjie

    there are error:

    F:\visual C++\Edit\richeditctrlex\RichEditCtrlEx.h(103) : error C2440: 'initializing' : cannot convert from 'class std::list<class CString,class std::allocator<class CString> >::const_iterator' to 'class std::list<class CString,class std::allocator<
    class CString> >::iterator'
    No constructor could take the source type, or constructor overload resolution was ambiguous
    F:\visual C++\Edit\richeditctrlex\RichEditCtrlEx.h(103) : error C2678: binary '!=' : no operator defined which takes a left-hand operand of type 'class std::list<class CString,class std::allocator<class CString> >::iterator' (or there is no acceptab
    le conversion)
    Error executing cl.exe.

  • need to extract bold text alone in rtf control in vb

    Posted by Legacy on 01/24/2002 12:00am

    Originally posted by: vikram

    hi all
    i was able to select a text and make it bold, now i want store the content in a file,the problem is that i want the text that was bold to be stored in the file with the tag <bold>, is it possible to find the text that has been made bold in rich text box control,
    thank you in advance

  • How to make it work with Unicode

    Posted by Legacy on 12/14/2001 12:00am

    Originally posted by: Hope

    This is a great project. But if I change project setting to have _UNICODE and recompiled, nothing was put out to the two edit window.
    Please help to get it work with Unicode.

    Thanks a million!!


  • Help about CRichEditCtrl in Windows 2000

    Posted by Legacy on 11/09/2001 12:00am

    Originally posted by: Ignacio Garcia

    In my application, i use a CRitchEditCtrl to show a text. I change the char type between Arial to Symbol, and i do it with the method SetSelectionCharFormat. But Windows 2000 don't change the char type because don't untherstand this method. I would like to know what can i do, if i have to use a library, or header file or if i need a compiler more actual. Thank you and sorry because my English is very bad.

  • need help: dealing with mouse in a richeditctrl

    Posted by Legacy on 07/04/2001 12:00am

    Originally posted by: sabine

    I need some help in dealing with this richeditctrl.
    i want to get any message or make any change when I click on the richeditctrl.
    I need some more help on the "CRichEditDtrl::FindText" function. I always get (-1) as its return value, eventhough the text i'm looking for is shown in the richeditctrl.
    I will be so greatful if anyone could help!

  • Need Help about Win Sockets

    Posted by Legacy on 12/18/2000 12:00am

    Originally posted by: Junaid

    i m developing urdu chat server for Lan's
    anybody to help in sockets

  • Column (Block) Marking by Alt + Left-Mouse-Down-Drag

    Posted by Legacy on 05/23/2000 12:00am

    Originally posted by: basava


    We need to implement this column marking in a rich-edit-ctrl. This feature is available in many editors - Msdev, MsWord etc. You can select a vertical block by dragging left-Mouse-down with Alt key pressed. You can cut, copy, delete or paste the column-marked selection. It is very useful feature in any edit control.

    Can anyone tell me how to enable this feature for rich-edit-control or how can it be implemented?


  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Enterprises are increasingly looking to platform as a service (PaaS) to lower their costs and speed their time to market for new applications. Developing, deploying, and managing applications in the cloud eliminates the time and expense of managing a physical infrastructure to support them. PaaS offerings must deliver additional long-term benefits, such as a lower total cost of ownership (TCO), rapid scalability, and ease of integration, all while providing robust security and availability. This report …

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date