Syntax coloring text edit window class | CodeGuru

Syntax coloring text edit window class

This class provides a CWnd derived editor that provides syntax coloring based on a keyword file you provide. It also supports auto-indent and retab. It is much faster than using CRichEditView to do the same thing, but it flickers a little and does not support any additional formatting. There are two classes that must be […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 6, 1998
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

This class provides a CWnd derived editor that provides syntax
coloring based on a keyword file you provide. It also supports
auto-indent and retab. It is much faster than using CRichEditView to
do the same thing, but it flickers a little and does not support any
additional formatting.

There are two classes that must be added to a project
“ColorEditWnd” is the editor and “Colorize” is the parser. The
included project shows how to add the window.

Add the window as follows:

Add a member variable which is a pointer to a ColorEditWnd (in
this example cColorWnd)

After initialization of the parent window instantiate the color
edit window as follows:

CRect client;

GetClientRect(client);

CString keywordsFile = “Keywords.ini”;

BOOL caseSensitive = FALSE;

long pCharDX = 10;

long pCharDY = 16;

long pTabSize = 4;

int pFontSize = 120;

CString pFontName = “Courier New”;

cColorWnd = new
ColorEditWnd(

this, //parent
window

client, //initial size and position

IDC_COLOR_WND, //id value

keywordsFile, //keywords file

caseSensitive, //case sensitive ?

pCharDX, //width of each character

pCharDY, //height of each character

pTabSize, //size of a tab in characters

pFontSize, //font size * 10 (I.E. 100 = 10)

pFontName); //the font name

cColorWnd->ShowWindow(SW_SHOW);

Use the methods “LoadText” and “UnloadText” to control the text in
the edit window. .

Keyword File

The keyword file is a simple text file with each word on a
separate line. Individual words will appear as keywords (blue), words
preceded by ‘&’ are user defined functions (red). If a word is
preceded by ‘+’ it causes an auto-indent, ‘-‘ causes an
auto-unindent.

The example project includes a keyword file for VBA.

Limitations

There is some flickering in the current version.

Download source – 41KB

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.