Click here to Skip to main content
15,901,205 members
Articles / Desktop Programming / MFC

ClassLib, A C++ class library

Rate me:
Please Sign up or sign in to vote.
4.80/5 (32 votes)
25 May 2005CPOL8 min read 403.4K   11.5K   141   116
C++ class library.


Version 2.9 and higher of the library will not support Visual C++ version 6.0 anymore. The library compiles cleanly under Visual Studio .NET 2003 with warning level 4. It should at least compile under Visual Studio .NET 2002 although this has not been tested. The provided solution is a Visual Studio .NET 2003 solution.


After having programmed mostly in C for about 10 years, I decided about a year ago that it was time to start learning C++. Because I was also trying to get to grips with the Win32 API, I decided to combine the two and create my very own class library. The result is what you see here. A library of C++ classes which mostly contain wrappers for Win32 data types etc.

I have always found that you learn the most from looking at other peoples' code. Do not be surprised if you find techniques and code in the library which are used in others code. Do not even be surprised when you see code which I have blatantly copied from the various sources I found on the net. I have tried to keep track of the source code and the people who originally wrote it. You will find a list further down.


The class library consists of:

  • Wrapper classes for windows and dialogs.
  • MDI support.
  • Bitmapped menus.
  • Wrappers for standard and common controls.
  • New control classes like BalloonHelp, ColorPicker, ColorPopup, Brainchild, DirBrowser, FileBrowser, FileDirTree, FlatButton, HyperLink, InfoBar, InfoControl, Splitter and many more.
  • XP style rendering support for the custom controls and an easy way to add XP style rendering to your own controls.
  • A complete layout-engine which enables you to create resizable GUIs with a little extra effort.
  • Collector classes for arrays, linked-lists and hash tables.
  • Wrappers for the Win32 GDI system including some utility classes.
  • A string class.
  • Some utility classes like BoyerMoore, Crc16, Crc32, DrawState, FindFile, Module, MRU, RectTracker, RegKey, RGBHLS, Theming and WaitCursor.

Getting Started

I have never been one for writing documentation (my employer can vouch for that ;)) so there is no documentation for this library. However, the source code has been commented quite extensively so it should not be a problem to get going with it. Also because most classes are simple wrappers, MFC/Win32 programmers should be able to get familiar with it fast.

Next to the commented source code there are also several sample programs which should be a good starting point.

Before you can get started, you must extract the files you get with the distribution somewhere onto your hard disk. Once you have done that, you should make the following settings in Visual Studio:

  1. Under the menu Tools->Options...
  2. Select VC++ Directories under the Projects item in the tree view.
  3. Select Include files in the Show directories for combo box.
  4. Add the directory in which the files where extracted to the Include files search path. I.e., if you extracted the library source files at D:\ClassLib, you add this path to the include files.
  5. Select Library files in the Show directories for combo box.
  6. Add the Classes\LIB directory to the Library files search path. I.e, if you extracted the library source files at D:\ClassLib, you add D:\ClassLib\LIB here.

This should get you started. To keep the size of the distribution down, the link-libraries are not included. Instead, a Visual Studio .NET 2003 solution is included which will enable you to create these libraries yourself. Double-click on the ClassLib.sln file in the distribution directory and Visual Studio will open. In it, you can select to build the "Win32 Release", "Win32 Debug", "Win32 Release Multithread" and "Win32 Debug Multithread" versions of the linker library. For each of the mentioned libraries, you can also compile a Unicode version.

The Samples archive includes a solution and sources which will enable you to compile the sample programs for this library.

Technical Details

The debug versions of the library will track a couple of things for you. First of all, memory leaks up to a degree. If for some reason you forget to free memory allocated using the new operator or using malloc() or calloc(), the code will assert upon exit showing a message that memory has not been freed. In addition to that, when you run the code under debugger control, the lines at which the unfreed memory was allocated are displayed. The standard Microsoft debug support in the C runtime library is used for this. Memory leaks caused by not freeing memory allocated not using the new operator or the C runtime library are not reported.

The debug libraries will also track created windows, GDI, device contexts, and menu objects. These are tracked internally in a list and when this list is not empty when the code exists, the program will assert telling you which list(s) were not empty.

The debug libraries will also track the GDI and device context handles which are created. If they are not destroyed properly before the code exits the program asserts upon exit.

Except for making sure your code cleans up after itself, there is nothing which needs to be done for the code to exit without asserting.

Another thing I would like to mention is that the new operator will throw an exception (see memoryexception.h) when it fails to allocate the requested memory.


As I mentioned above, some of the code in this library is based on the work of other people. Here is a list of the people whose code I have used as an example and sometimes as-is. Thanks to you all.

  • Chris Maunder

    The ClsColorPopup (sorry for the American spelling ;)) class which I have adapted to run with this class library. The class has undergone several code changes which include blend or roll animation when the window opens and XP style rendering when the app is themed and running under XP. The ClsComboCompletion class is also a class he wrote which I adapted for this library.

  • Joshua Heyer:

    The ClsBalloonHelp class. I have adapted this class for this library. I have made several changes to the original code which include another way of blending using the AnimateWindow() API instead of SetLayeredWindowAttributes() and timers. I have also bypassed the need to use a timer for the hot-tracking of the close button. Last but not least, it supports text styles in the body text and it uses an XP style close button when running themed under XP.

  • The Microsoft knowledge base article Q29240.

    I have used the code from this article to create the ClsRGBHLS class. This class can be used to convert RGB colors to HLS values and vice versa.

  • ????

    The ClsString class uses a method of buffer-sharing which I found in a string class from a class library written for Windows CE. I am sorry to say that I do not remember who wrote the thing but if you know who, let me know so I can give credit where credit is due.

  • Todd Osborne

    I have used his VXCL library for two things. First, the Windows procedure used by the ClsWindow class is largely based on his work. Secondly, the common dialog wrappers are partly based on his work.

  • Joseph M. Newcomer

    I have used his "Using Worker Threads" article to base the ClsWorkerThread class on.

  • Paolo Messina and Jerzy Kaczorowski

    The ClsHotButton code contains their COddButton code which takes care of the problems you usually get when trying to combine ownerdraw buttons and a default state.

  • Bruno Podetti

    I have used his hooking / subclassing technique to enable custom frames on ClsMenu derived menu classes.

  • Christian Graus

    The GetGrayscaledBitmap() method in ClsBitmap is based on the hit "Per-Pixel" filters article.

  • Carlos Antollini

    The ADO and ADOX classes are originally written by him.

  • Daniel Bowen

    The library contains a port of his CustomTabCtrl code. Not all classes have been ported but the most important ones are. The library has a port of his DotNetTabCtrl, DotNetButtonTabCtrl and FolderTabCtrl. Of course the base CustomTabCtrl has been ported as well.

I hope I did not forget anybody here. If I did it was by mistake, not by choice.

Changes (2.9 -> 3.0)

  1. Added solutions for compiling Unicode versions of the library. Note however that the Unicode support is untested.
  2. Added ClsPanelBar, ClsPanel, ClsOutlookBar and ClsXPOutlookBar classes.
  3. Made several small adjustments and additions to several classes.
  4. Added a port of Daniel Bowen's excellent CustomTabCtrl.
  5. Due to the port, I have also added a few macros which make message cracking a little bit easier. Though the macros are not compatible with the ATL/WTL message cracking macros, they do resemble them.
  6. Various tweaks and additions.
  7. Fixed numerous bugs.

Changes (2.7 -> 2.9)

A lot of fixes, tweaks and additions have been implemented in this release. Major changes for this release are:

  1. Ported the ADO and ADOX classes by Carlos Antollini.
  2. Added support for custom window frame rendering including standard and user defined buttons in the window frame.
  3. Added a RichEdit wrapper.
  4. Added classes for hot-trackable normal and XP style editboxes and comboboxes.

For a complete list of changes, take a look at the History.txt file in the source code Zip file.


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

Written By
Software Developer (Senior)
Netherlands Netherlands
I have been programming for a hobby since 1985. I have started programming on the C= 64. After that I migrated to the C= Amiga which I traded in for a PC back in 1997 I believe. Back in 2000 I decided to lose a hobby and start developing software for a living.

Currently I am working mainly in developing software for building security and access control systems.

Comments and Discussions

GeneralRe: Docking toolbar / dialog / frame ? Pin
desccode29-Sep-04 19:05
desccode29-Sep-04 19:05 
GeneralRe: Docking toolbar / dialog / frame ? Pin
Jan van den Baard29-Sep-04 19:33
professionalJan van den Baard29-Sep-04 19:33 
GeneralRe: Docking toolbar / dialog / frame ? Pin
desccode30-Sep-04 19:43
desccode30-Sep-04 19:43 
GeneralAnything exists but no ClsRichedit Pin
gri27-Jul-03 2:47
gri27-Jul-03 2:47 
GeneralRe: Anything exists but no ClsRichedit Pin
Jan van den Baard27-Jul-03 19:45
professionalJan van den Baard27-Jul-03 19:45 
GeneralRe: Anything exists but no ClsRichedit Pin
Jan van den Baard7-Aug-03 4:37
professionalJan van den Baard7-Aug-03 4:37 
GeneralRe: Anything exists but no ClsRichedit Pin
gri7-Aug-03 12:28
gri7-Aug-03 12:28 
Generalneed IP help Pin
prit14-Apr-03 7:41
prit14-Apr-03 7:41 
i am working on a Image Processing project, i need algo/code on morphology,finding skeleton of a video camera image,Regional descriptors....
can anybody plz guid me
my email id is

Generalsecurity programming Pin
Reza Shademani6-Apr-03 6:41
Reza Shademani6-Apr-03 6:41 
Questionhelp? Pin
psusong28-Mar-03 20:40
psusong28-Mar-03 20:40 
AnswerRe: help? Pin
Jan van den Baard28-Mar-03 23:04
professionalJan van den Baard28-Mar-03 23:04 
GeneralRe: help? Pin
Frank De prins8-Apr-03 20:06
Frank De prins8-Apr-03 20:06 
GeneralRe: help? Pin
Jan van den Baard10-Apr-03 21:16
professionalJan van den Baard10-Apr-03 21:16 
Generalsuggestion Pin
xuell0025-Mar-03 21:04
xuell0025-Mar-03 21:04 
GeneralClsStringArray Pin
2374125-Feb-03 6:25
2374125-Feb-03 6:25 
GeneralRe: ClsStringArray Pin
Jan van den Baard27-Feb-03 19:30
professionalJan van den Baard27-Feb-03 19:30 
GeneralRe: ClsStringArray Pin
rspilon27-Feb-03 21:27
rspilon27-Feb-03 21:27 
GeneralBuild problem. Pin
soup6-Dec-02 6:37
soup6-Dec-02 6:37 
GeneralRe: Build problem. Pin
Anonymous17-Dec-02 22:32
Anonymous17-Dec-02 22:32 
GeneralRe: Build problem. Pin
codeMajor18-Jan-03 9:37
codeMajor18-Jan-03 9:37 
GeneralRe: Build problem. Pin
Simon Steele24-Feb-03 6:22
Simon Steele24-Feb-03 6:22 
GeneralWONDERFUL Class!! Pin
Joseph Italy8-Oct-02 23:48
sussJoseph Italy8-Oct-02 23:48 
GeneralWrong source URL Pin
Jan van den Baard2-Aug-02 1:01
professionalJan van den Baard2-Aug-02 1:01 
GeneralRe: Wrong source URL Pin
Jan van den Baard7-Aug-02 19:39
professionalJan van den Baard7-Aug-02 19:39 
QuestionXP style rendering? Pin
Neville Franks7-Jun-02 13:06
Neville Franks7-Jun-02 13:06 

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.