Click here to Skip to main content
12,954,403 members (95,293 online)
Click here to Skip to main content
Add your own
alternative version


28 bookmarked
Posted 5 Feb 2002

Syntax Highlighter

, 5 Feb 2002
Rate this:
Please Sign up or sign in to vote.
An application to generate highlighted code RTF files
<!-- Download Links -->


How often would we like to insert coloured code in our documents? I know it's not that important but, first, it looks much nicer and, second, it's much easy to understand a piece of source code when it is coloured. At least for me.

What this little application does is exporting Rich Text Format syntax coloured code. To do that, special text files are used defining the each of the languages that the application will handle and colour. These files are found in the application folder.

Sample Image

Language files

Let's have now a look into this language files. From all the sections, only the first one is not optional, the rest of them are, though it doesn't make a lot of sense not including them.

§ Language extensionsFile extensions for which the language file will be used
§ Comment lineComment line indicator (e.g.: // in C++)
§ Comment blockOpening and closing comment block symbols (in different lines)
§ String marksCharacters that can enclose a string (e.g.: ")
§ OperatorsSingle characters that act as operators in the described language in a single line. (blank spaces can be added)
§ KeywordsLanguage keywords.
§ Colours (normal, comment, string, keyword, operator)Colour in hexadecimal that will be used. One per line.

Note that an empty line is required after the last element of each section and the section names must be exactly like they appear in the table above.


First of all, saying that the application may have bugs. I'm not speaking about memory leaks or something like that, just pointing out the possibility that somebody gets a bad coloured output for a given source file. I haven't so far anyway.

I've only tested the app under Windows 2000, but it should work as well under Windows 98 and I guess also in WindowsXP (?)

Two of those language files are included in both of the downloads. One for C/C++ and the other one for Visual Basic

The code to transfer the rtf information to a CString object was borrowed from the article Painless streaming with CRichEditCtrl, that can be found in the Docs sections in

I'm posting the source code along with the application. I hope this article helps, in the same way many of the articles found here, in the Code Project, helped me.

Salu2, Samuel.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Samuel Gonzalo
Software Developer (Senior)
Spain Spain
I studied Telecommunication with spezialization in Sound & Image. I was always very interested in programming at university as well and that is how I earn a living.

Since some years ago, I am also succesfully involved in software architecture and design.

You may also be interested in...

Comments and Discussions

GeneralNice article Pin
er.vks18-Oct-16 21:00
memberer.vks18-Oct-16 21:00 
GeneralThanks for the ref Pin
PaulMdx31-Oct-05 1:51
memberPaulMdx31-Oct-05 1:51 
GeneralCrash if no valid language extension found Pin
UTO7-Jun-04 23:41
memberUTO7-Jun-04 23:41 
Generalsource files link is not working :-((( Pin
Anonymous6-Feb-02 21:23
memberAnonymous6-Feb-02 21:23 
GeneralRe: source files link is not working :-((( Pin
Samuel Gonzalo6-Feb-02 23:57
memberSamuel Gonzalo6-Feb-02 23:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 6 Feb 2002
Article Copyright 2002 by Samuel Gonzalo
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid