dcsimg

Keyword coloring edit control

WEBINAR:
On-Demand

Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame


.

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.

  1. I wanted to try out several of the classes found on the www.codeguru.com 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 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 - 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 keithr@europa.com with suggestions, fixes, or questions.



Most Popular Programming Stories

More for Developers

RSS Feeds

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