Click here to Skip to main content
15,860,943 members
Articles / Desktop Programming / MFC
Article

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 397.8K   11.5K   141   116
C++ class library.

Note

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.

Introduction

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.

Features

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.

Thanks

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.

License

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

 
Questionmissing type specifier - int assumed Pin
Member 1208785426-Mar-16 22:06
Member 1208785426-Mar-16 22:06 
GeneralMy vote of 5 Pin
duck5tar23-Apr-13 3:39
duck5tar23-Apr-13 3:39 
GeneralMy vote of 4 Pin
buyong26-Sep-11 15:11
buyong26-Sep-11 15:11 
GeneralVS2008 port Pin
e_ilite9-Feb-10 19:33
e_ilite9-Feb-10 19:33 
GeneralRe: VS2008 port Pin
Sci_fie1-Jun-10 3:55
Sci_fie1-Jun-10 3:55 
GeneralRe: VS2008 port Pin
Member 1208785426-Mar-16 22:03
Member 1208785426-Mar-16 22:03 
GeneralRe: VS2008 port Pin
e_ilite4-Sep-11 15:16
e_ilite4-Sep-11 15:16 
GeneralRe: VS2008 port Pin
Member 1208785426-Mar-16 22:03
Member 1208785426-Mar-16 22:03 
GeneralRe: VS2008 port Pin
e_ilite27-Mar-16 4:00
e_ilite27-Mar-16 4:00 
QuestionUpdate? Pin
Satervalley24-Oct-08 6:36
Satervalley24-Oct-08 6:36 
AnswerRe: Update? Pin
Jan van den Baard26-Oct-08 20:52
professionalJan van den Baard26-Oct-08 20:52 
GeneralRe: Update? Pin
e_ilite20-Feb-10 13:58
e_ilite20-Feb-10 13:58 
GeneralRe: Update? Pin
Member 1208785426-Mar-16 20:32
Member 1208785426-Mar-16 20:32 
GeneralRe: Update? Pin
e_ilite27-Mar-16 3:57
e_ilite27-Mar-16 3:57 
GeneralNot compiling -- missing type specifier - int assumed Pin
JonWiesman16-Jan-07 6:36
JonWiesman16-Jan-07 6:36 
GeneralRe: Not compiling -- missing type specifier - int assumed Pin
Jan van den Baard16-Jan-07 19:40
professionalJan van den Baard16-Jan-07 19:40 
GeneralRe: Not compiling -- missing type specifier - int assumed Pin
Jan van den Baard19-Jan-07 9:41
professionalJan van den Baard19-Jan-07 9:41 
GeneralRe: Not compiling -- missing type specifier - int assumed Pin
JonWiesman21-Jan-07 7:17
JonWiesman21-Jan-07 7:17 
GeneralRe: Not compiling -- missing type specifier - int assumed Pin
balconysun11-Feb-07 5:09
balconysun11-Feb-07 5:09 
GeneralRe: Not compiling -- missing type specifier - int assumed Pin
Sebasthian7312-Feb-07 10:57
Sebasthian7312-Feb-07 10:57 
GeneralRe: Not compiling -- missing type specifier - int assumed Pin
lweaver28-Apr-07 13:48
lweaver28-Apr-07 13:48 
I would like to get a copy for VS 2005 as well.

lw@lwconsulting.com


Thanks,

Larry
GeneralRe: Not compiling -- missing type specifier - int assumed Pin
Free99911-Jun-07 11:21
Free99911-Jun-07 11:21 
GeneralRe: Not compiling -- missing type specifier - int assumed Pin
Member 1208785426-Mar-16 22:02
Member 1208785426-Mar-16 22:02 
QuestionOlder versions available? Pin
JesperA11-Jan-06 17:51
JesperA11-Jan-06 17:51 
AnswerRe: Older versions available? Pin
Jan van den Baard11-Jan-06 19:44
professionalJan van den Baard11-Jan-06 19:44 

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.