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"));
m_text.AddKeyword(_T("static"));
m_text.AddKeyword(_T("char"));
m_text.AddKeyword(_T("short"));
m_text.AddKeyword(_T("unsigned"));
.
.
.
}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.
- I wanted to try out several of the classes found on the
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 www.codeguru.com.
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
-I'm open to adding change request to my ToDo list for this application. Feel free to contact me at
keithr@europa.com with suggestions, fixes, or questions.

Comments
How to extend the keywords ?
Posted by Legacy on 06/13/2003 12:00amOriginally posted by: sp30
If for some reason,I want to add some keywords different from the default ones, how to meat with this requirement?
ReplyHelp Me!
Posted by Legacy on 09/09/2002 12:00amOriginally 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.
Thanx.
ReplyJohnie
There is a error in the Undo/Redo
Posted by Legacy on 05/30/2002 12:00amOriginally posted by: jim
ReplyExcellent
Posted by Legacy on 01/17/2002 12:00amOriginally posted by: Henyi Jen
I am currently working on a simulation program and I need
Replya color-coded editor. Your is a must-have. Thank you!
Coloring Edit
Posted by Legacy on 03/08/1999 12:00amOriginally 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.
Sincerely.
Seong-Gyu Choi
Reply