Click here to Skip to main content
13,292,670 members (63,343 online)
Click here to Skip to main content
Add your own
alternative version


35 bookmarked
Posted 24 Jun 2010

A DevStudio-Like Application with a Variety of UI Components

, 26 Jul 2010
Rate this:
Please Sign up or sign in to vote.
A MFC application featuring a syntax coloring text editor, DevStudio-like toolbar, status bar, and output window, and multithreaded computing


In this article, I will present an academic application WinCalcCT I recently developed as a software product of my research. It accepts min-max functions description files (which I will explain shortly) and then computes the cycle time vectors of the min-max functions on request. This application utilizes MFC’s document/view architecture. Since min-max functions description files (*.mmf) are text files, the view class (CWCTView) largely implements what a text editor needs to have. However, like *.cpp files, there is a syntax, albeit much simpler, for *.mmf files, so we need a syntax coloring editor. In addition, we need a place to display the computation results, and that is the output window. Moreover, as we apparently don’t want to freeze the user interface while computing, multithreading is needed. All these features are now implemented in WinCalcCT.

WinCalcCT, with the above features, is quite like a greatly simplified Microsoft Developer Studio, and, with this in mind, I have tried to make the appearance of the UI components in WinCalcCT as DevStudio-like as I can. I fortunately need not do this from scratch since there have been several classes designed by other authors that I can reuse.

It is my conjecture that many MFC developers will welcome my application because often times they would be assigned similar tasks and my source code could then provide a good starting point.


This application stems from my previous research “On Discrete Event Systems Modelled by Min-Max Functions”. An example of a 2-dimensional min-max function is F[x1,x2]=[min(x1+2,max(x2,x1+4)), max(x1-3,x2)]. A central performance measure of such systems (or functions) is their cycle time vector, or simply cycle time, which indicates their throughput. Mathematically, given a min-max function F, its cycle time exists and is unique. An efficient, and arguably the only realized algorithm was designed by the present author and was published in a scholarly journal (see readme.txt in the source package for details).

The Syntax Coloring Editor

Aside from syntax coloring, this version of WinCalcCT text editor supports keyboard editing, text scrolling, caret showing, selection processing and showing, clipboard cut/copy/paste, text find, and so on. My next task is to add text replace and edit undo and redo.

Worth a mention is that the class CWCTView is derived from CView instead of CEditView or CRichEditView as many people would expect. CEditView is not a choice because it does not support syntax coloring, and although CRichEditView does support syntax coloring, I found the text in a CRichEditView quite ugly. In fact, Microsoft Visual Studio itself took the same approach as I did, you can confirm this by using Spy++.

It is believed that my implementation of syntax coloring is very unique. Usually, there is an analyzing (or parsing, against the syntax) phase before the rendering of the text. In WinCalcCT, there is no independent analyzing phase and there is even no data structure representing analyzed or parsed text. This is not to say that this is a better approach, but I can at least argue that this simplifies code writing and could be a viable choice if the syntax is line-based instead of block-based, as for most assembly languages and many script languages.

CWCTView currently does not support displaying a tab character as four or eight spaces and regarding the spaces as a single editing unit. This is because in our context the feature is not needed. It may involve a fair amount of work to add this feature.


The Output Window

A truly Windows output window is very handy and useful, and many people want it. WinCalcCT's output window is designed to display read-only text messages. New output strings are appended to the old content. Using the output window is as easy as using printf() for the character console. In the main thread, to display a string str in the output window, one needs only write:

AfxGetMainWnd()->SendMessage(WM_USER_NEW_OUTPUT, 0, (LPARAM)(LPCSTR)str) 

In WinCalcCT, output strings are issued from the worker thread, so a pointer to the application's main window object needs to be included in the thread parameters.

The non-client portion (or the frame) of the output window is based on the CSizingControlBar class by Cristi Posea. However, I have made several modifications to the code to make the frame much more DevStudio-like and look more professional. Code for the client portion of the output window is my own work. It did not take me much time, since it virtually needs only a subset of the features of CWCTView.

Other Useful UI Components

The DevStudio-like toolbar in WinCalcCT is a slight modification of the CToolBarEx class written by Joerg Koenig. The DevStudio-like status bar is basically my own work based on CStatusBar, though I owe inspirations to many other status bar authors. I used Chris Maunder's progress bar without any modification.

Multithreaded Computing

The relevant code for worker thread creation and synchoronization between the main thread and the worker thread is largely based on Jeff Prosise’s book “Programming Windows with MFC”. I have added code to deal with the situation where the user attempts to close a document when it is in the course of computing.

Using the Code

The CWCTView class is not meant for derivation, developers can copy the relevant code to their own code file. Note that although CWCTView is based on CView, nearly all of its user-interface features still hold even if it is based on CWnd.

To use the output window, be sure to include OutputFrm.cpp, OutputWnd.cpp, OutputWndCaret.cpp, and OutputWndScroll.cpp in your project, and create the output window in the OnCreate method of the main frame window.

The CDevStatusBar class is also not meant for derivation. Developers are expected to have a fair understanding of my code to reuse it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Yiping Cheng
Software Developer
China China
Yiping Cheng is both a software developer and a researcher. He has been programming in C/C++ for over 15 years. His favorite platform is Windows and he loves using MFC to build full-fledged Windows applications. When he is not programming or researching, he enjoys listening to traditional opera and music.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
Aric Green11-Jul-10 16:57
memberAric Green11-Jul-10 16:57 
GeneralRe: My vote of 1 [modified] Pin
Frank (Yiping) Cheng12-Jul-10 11:43
memberFrank (Yiping) Cheng12-Jul-10 11:43 

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.171207.1 | Last Updated 26 Jul 2010
Article Copyright 2010 by Yiping Cheng
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid