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 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



Comments

  • It works slowly

    Posted by wangyu0831 on 12/27/2007 10:56pm

    It works slowly

    Reply
  • Some problem with ComboBox

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

    Originally posted by: kim

    use this class with combobox..
    there is no cursor in editbox

    Reply
  • ExEditors Library

    Posted by Legacy on 03/19/2002 12:00am

    Originally posted by: Mike Philips

    A complete collection of editors in a single file:
    
    

    http://www.exontrol.com/sg.jsp?content=products/exeditors

    Regards,
    Mike

    Reply
  • Thinks for you advise!!

    Posted by Legacy on 02/03/2002 12:00am

    Originally posted by: DZBJET

    i'm very astonished by this article,
    and i've been searching for this article for a long time.
    thank you!

    Reply
  • Ack! Win XP Error

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

    Originally posted by: John

    It is probably Windows XP. I got an error report popup box saying:
    'SYNTAXCOLORDEMO MFC Application has encountered a problem and needs to close. We are sorry for the inconvenience.'

    Just wanted to make this known.

    ~good luck

    Reply
  • Oh Fuck Yeah...

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

    Originally posted by: hbk003

    This is some of the best work I've seen...

    Reply
  • It works like shit!

    Posted by Legacy on 10/01/2001 12:00am

    Originally posted by: P

    Nice work of shit!

    Reply
  • Bug in ColorEditWnd::DrawLine(long pLine) function

    Posted by Legacy on 01/20/1999 12:00am

    Originally posted by: Sergey Kornilov

    See the 11-th line in this function:
    
    y = pLine * CharDY - cTheText.cFirstLine;

    Should be:
    y = pLine * CharDY - cTheText.cFirstLine*CharDY;

    When I tryed to scroll text in window by up-down key pressing
    I always saw strange things. The problem was in invalid Y value
    calculation. Now it works correctly.

    Reply
  • Syntax Coloring Text Edit Window

    Posted by Legacy on 12/23/1998 12:00am

    Originally posted by: Ron Royce

    I noticed that the functionality for using the shift key to highlight words is not implemented. This is a necessity for any text editor.

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

Top White Papers and Webcasts

  • Microsoft® Office 365 is a top choice for enterprises that want a cloud-based suite of productivity/ collaboration applications. With Office 365, you get access to Microsoft™ Office solutions practically anytime, anywhere, on virtually any device. It's a great option for current Microsoft users who can now build on their experience with Microsoft™ solutions while enjoying the flexibility of a cloud-based delivery. But even organizations with no previous investment in Microsoft will find that …

  • Whether you're just now developing your first mobile app, refining an existing one, or deploying multiple apps, the process for doing so can be complicated. Utilizing a Rapid Mobile Application Development (RMAD) platform can help you not only make that process easier, but also help the business reach its goals in a timely, cost-efficient manner. This eBook outlines seven key factors to consider as you choose the right RMAD platform to meet your needs, and includes a quick-reference checklist.

Most Popular Programming Stories

More for Developers

RSS Feeds

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