Keyword coloring edit control


Download the project. 238KB. Note that this is still work in progress and Keith is open to suggestions. This project requires VC++ 5.0 or later, don't expect to have an easy time of build this project under VC++ 4.2 or earlier.

About The Project

This project implements a simple color encoding text editor, which is similar to the editor found in Visual C++ or Visual Basic. It allows the developer to configure the encoding of keywords and comments. This project is an MDI application.

Defining the Color Encoding

The encoding is defined in the constructor for the CDocument derived class CColorEditDoc. The default configuration looks like the following:

CColorEditDoc::CColorEditDoc() : CUndo(25, 64*1024)
	m_text.AddComment(_T("/*"), _T("*/"));
	m_text.AddComment(_T("//"), _T("\n"));

The definitions for defining a keyword or comment are as follows.

	// Color Coding
	BOOL AddKeyword(const CString& keyword, COLORREF color = RGB(0, 0, 200));
	BOOL AddComment(const CString& begin = _T("//"), const CString& end = _T("\n"), COLORREF color = RGB(0, 200, 0)); 

Notice that you can specify a unique color for every keyword and comment definition.

Goals of the Project

I wrote this project for three reasons.

  1. I wanted to try out several of the classes found on the webpage.
  2. I wanted try out a real example of a worker thread.
  3. I wanted to have a Color Encoding Text Editor in my toolbox of royalty free source code.

However, this project has turned into my toolbox. I've placed many often used techniques in this project such as printing support, cut/copy/paste support, undo/redo, flicker free updates and so forth. I've found myself using the project as a place to pull working code out into other projects.

New Features

Dragging during a selection will now scroll the window. I've fixed several problems and have one know unresolved bug. Color encoding quotes is now supported.

Known Bugs

The editor won't scroll beyond 1500 lines on Win95. I suspect this is due to a limitation in the size of the GDI area in MM_TEXT. If anyone has some ideas for working around this, please let me know.

Classes Used

This project uses the following classes found at

CUndo - Undo/Redo for CDocument derived classes
CMemDC - Double buffering class for drawing
CSplash255Wnd - 256 color splash screen support
CToolBarEx - Flat toolbar support
CRegExp - Regular Expression matching
CStringEx - Extended Cstring
CProgressBar - A progress indicator on the status bar.
CClockStatusBar - Adds a clock to the status bar.
CCreditStatic - Scrolls text in a static text field.

In addition it defines the class:

CColorString - CString plus rule based color encoding

I'm open to adding change request to my ToDo list for this application. Feel free to contact me at with suggestions, fixes, or questions.


  • How to extend the keywords ?

    Posted by Legacy on 06/13/2003 12:00am

    Originally posted by: sp30

    If for some reason,I want to add some keywords different from the default ones, how to meat with this requirement?

  • Help Me!

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

    Originally posted by: Johnie

    I need an OCX control which enables a richtextbox to colorize the keywords. Can you help me please? I want to use it in a VB application.


  • There is a error in the Undo/Redo

    Posted by Legacy on 05/30/2002 12:00am

    Originally posted by: jim

    first,input 10 letter and Undo 5 letter,then input a letter ,will be a error.

    the First(input) : 1234567890
    the second(Undo 5 time) :12345
    the third(input 'a' letter):12345īīīīa

  • Excellent

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

    Originally posted by: Henyi Jen

    I am currently working on a simulation program and I need
    a color-coded editor. Your is a must-have. Thank you!

  • Coloring Edit

    Posted by Legacy on 03/08/1999 12:00am

    Originally posted by: Seong-Gyu Choi

    Thank you very much for publishing the coloring editor.
    It's a precious code to me.
    I am checking the code very carefully.
    Again, thank you for it.

    I'm very sorry, but I found the bug at coloring edit.
    There are special-key stroke problem, scrollbar problem, and program down at the paste mode after several undo.

    If you have new code correcting the bugs, would you please send me
    the new code.

    If you send the code, it will be very helpful to me.


    Seong-Gyu Choi

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

Top White Papers and Webcasts

  • Live Event Date: May 16, 2017 @ 1:00 p.m. ET / 10:00 a.m. PT Developers who use popular JavaScript frameworks like React to build user interfaces often have to create components to build the interface. Building components is time consuming, has integration and maintenance risks, and worst of all, distracts them from the task at hand -- actually building the app. Attend this webinar to see how to quickly and easily add more than 115 professionally supported and tested components from Sencha to your React …

  • Like many roles in the C-Suite, the CIO role is also changing. Its impact and control have been circumvented by cloud computing, the consumerization of IT, and employees that now have unprecedented access to technology. The role of the CIO is at a critical juncture. For some CIOs, the changing landscape reduces their scope of influence. For others, it means unprecedented opportunity. This eBook explores the changes that CIOs are experiencing today and how these executives can leverage their expertise to help …

Most Popular Programming Stories

More for Developers

RSS Feeds

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