Click here to Skip to main content
15,881,804 members
Articles / Desktop Programming / MFC
Article

VisualClassBuilder - Free Code Generation Tool

Rate me:
Please Sign up or sign in to vote.
3.87/5 (21 votes)
15 Feb 20073 min read 72.7K   2.2K   74   17
A free C++ code generator tool with source code.
Sample image

Introduction

This article is about a free C++ code generator tool. The code generator does what its name says: it generates source code based on an object model (like a UML class diagram), which represents the logical structure of your classes. It also helps you develop your applications faster and change things inside their structure, using a graphical user interface.

Using the Application

This submission is a tool, so the source code will not be discussed here. Instead, I will discuss how to use the tool.

The code generator has a graphical user interface by which you can build and manipulate simple UML class definitions on the screen. To insert a new class, select the Insert->Class... option from the main menu. The new class object will appear on the screen. You can place it wherever you want by dragging it. Similarly, to insert a new struct, select Insert->Struct... from the main menu and the new struct object will appear on the screen.

To change a class's settings, double click on the class object. The following dialog box will appear:

ClassOptionsDialog - General Page

Here, you can change the names of the class and its header and implementation files. You can also add author information and a short class description.

On the next page you can add member variables and properties to your class:

ClassOptionsDialog - Class Members Page

The settings on this tab page will be easily recognizable by C++ developers, so I will not waste space in this article by explaining them all in detail. The interesting option here is the Declare as property checkbox which, when enabled, will cause a pair of accessor methods (GetPropertyName() and SetPropertyName()) to be added to read/write values directly to the member variable. You have to specify a name for the property before you add it.

The next tab page is for class methods:

ClassOptionsDialog - Class Methods Page

Just as you can add member variables, you can also add class methods by declaring them on this tab page. A default method body will be generated in the class implementation file.

There are also additional class settings that you can change:

ClassOptionsDialog - Other Settings Page

Here you can add inheritance parents to this class (the classes that current class is derived from), include MFC precompiled headers, and turn on/off comment generation. Comments are important since the code can turn into a real mess later, and you will not be able to find what you need if you don't add explanations to what you create.

Working with structs is simpler than working with classes so I will not take the time to explain it.

Using the Results

After you build your class diagram you can select Build->Generate files option from the main menu and VisualClassBuilder will generate the required C++ files in the default output directory for you. From there, you can add them to your Visual Studio (or other) project.

Also, you can print the class diagram you have built by selecting File->Print from the main menu. To save your work, use File->Save. To load a saved project, use File->Open.

Points of Interest

I needed a tool like this one to speed up my work on different projects that use a similar class structure, so that I could avoid having to write the same source code multiple times.

VisualClassBuilder v1.0 features:

  • Class generation
  • Struct generation
  • Class inheritance support
  • MFC precompiled header support
  • Comments generation
  • Project saving/loading
  • Class diagram printing

License

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


Written By
Software Developer (Senior) Elektromehanika d.o.o. Nis
Serbia Serbia
He has a master degree in Computer Science at Faculty of Electronics in Nis (Serbia), and works as a C++/C# application developer for Windows platforms since 2001. He likes traveling, reading and meeting new people and cultures.

Comments and Discussions

 
Questionmissing line Pin
merano9930-Nov-21 13:51
mvemerano9930-Nov-21 13:51 
"...will generate the required C++ files in the default output directory for you."

The exe file does not run on Win10, so i just compiled it from source an it does not run.
The check, if the outputfile is open was missing and this ends in Programm crash for me.
First I added a Check for this to prevent a crash later.
C++
// Open output directory and file
BOOL rtn; 
strOutput.Format(_T("output/%s"), m_lpszClassHeaderFile);
rtn = outputFile.Open(strOutput, CFile::modeCreate | CFile::modeWrite);

// check file open here!!
if (rtn == 0) {
	MessageBox(NULL, _T("Cant open output file!"), _T("Error"), MB_OK);
	return;
}

The MessageBox apears and prevents a crash. For me this does nor work.
Found that before outputFile.Open() a line like
C++
rtn = CreateDirectory(_T("output"), NULL);

should be inserted to avoid the error.
QuestionVC 6.0 (Qt) Pin
cnvsudheer4-Nov-09 21:52
cnvsudheer4-Nov-09 21:52 
Generalclarification needed Pin
raghull27-Feb-07 20:32
raghull27-Feb-07 20:32 
Questionto clarify the doubt Pin
raghull27-Feb-07 18:26
raghull27-Feb-07 18:26 
AnswerRe: to clarify the doubt Pin
darkoman3-Mar-07 2:51
darkoman3-Mar-07 2:51 
GeneralVery Useful :) Pin
Programm3r22-Feb-07 3:26
Programm3r22-Feb-07 3:26 
Generallink error Pin
bruno leclerc18-Feb-07 23:04
bruno leclerc18-Feb-07 23:04 
GeneralRe: link error Pin
darkoman18-Feb-07 23:24
darkoman18-Feb-07 23:24 
GeneralRe: link error Pin
bruno leclerc19-Feb-07 2:52
bruno leclerc19-Feb-07 2:52 
GeneralUnicode builds Pin
NGS 54967217-Feb-07 10:08
NGS 54967217-Feb-07 10:08 
GeneralSuggestion Pin
Hans Dietrich16-Feb-07 1:35
mentorHans Dietrich16-Feb-07 1:35 
GeneralRe: Suggestion Pin
darkoman16-Feb-07 3:04
darkoman16-Feb-07 3:04 
GeneralRe: Suggestion Pin
J. Dunlap16-Feb-07 4:29
J. Dunlap16-Feb-07 4:29 
GeneralTypo mistake Pin
Priyank Bolia16-Feb-07 0:18
Priyank Bolia16-Feb-07 0:18 
AnswerRe: Typo mistake Pin
darkoman16-Feb-07 3:08
darkoman16-Feb-07 3:08 
NewsRead this before start Pin
darkoman15-Feb-07 22:27
darkoman15-Feb-07 22:27 
GeneralRe: Read this before start Pin
MikeTheDwarf4-Oct-07 4:50
MikeTheDwarf4-Oct-07 4:50 

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.