Click here to Skip to main content
15,867,308 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 398.1K   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

 
GeneralRe: Great Library, nice effort Pin
Jan van den Baard22-Jun-05 2:01
professionalJan van den Baard22-Jun-05 2:01 
QuestionCScrollView ? Pin
desccode4-Mar-05 6:02
desccode4-Mar-05 6:02 
AnswerRe: CScrollView ? Pin
Jan van den Baard6-Mar-05 19:22
professionalJan van den Baard6-Mar-05 19:22 
GeneralRe: CScrollView ? Pin
desccode6-Mar-05 19:42
desccode6-Mar-05 19:42 
GeneralRe: CScrollView ? Pin
Jan van den Baard7-Mar-05 7:31
professionalJan van den Baard7-Mar-05 7:31 
QuestionClsTracker About ? Pin
desccode25-Feb-05 19:41
desccode25-Feb-05 19:41 
AnswerRe: ClsTracker About ? Pin
desccode28-Feb-05 21:43
desccode28-Feb-05 21:43 
QuestionHow to set alignment and transparent background for ClsHyperLink? Pin
Stephan Brenner23-Feb-05 8:55
Stephan Brenner23-Feb-05 8:55 
Thanks for this great library.

Could you help me with a problem I have? I'm using ClsHyperLink within a ClsMDIChildWindow. The code below is used to create the hyperlink. It displays up, but it is not possible for me to set a transparent background and left alignment. How can I make this work?

TCHAR lpszLogFolder[] = _T("C:\\Programme");
m_FolderLink.Create(this, ClsRect(0, 0, 0, 0), (UINT)-1, lpszLogFolder,
WS_CHILD | WS_TABSTOP | WS_VISIBLE | BS_PUSHBUTTON | BS_LEFT);
m_FolderLink.Transparent() = TRUE;
m_FolderLink.URL() = lpszLogFolder;

Thanks,
Stephan
AnswerRe: How to set alignment and transparent background for ClsHyperLink? Pin
Jan van den Baard23-Feb-05 9:41
professionalJan van den Baard23-Feb-05 9:41 
QuestionPrecompiled Header errors with ADO? Pin
Williamgf11-Feb-05 9:26
Williamgf11-Feb-05 9:26 
AnswerRe: Precompiled Header errors with ADO? Pin
Jan van den Baard15-Feb-05 12:07
professionalJan van den Baard15-Feb-05 12:07 
QuestionUnicode support? Pin
gri5-Feb-05 1:10
gri5-Feb-05 1:10 
AnswerRe: Unicode support? Pin
Jan van den Baard7-Feb-05 19:48
professionalJan van den Baard7-Feb-05 19:48 
GeneralPutting controls inside Balloon Help control Pin
domKing11-Jan-05 4:26
domKing11-Jan-05 4:26 
QuestionPrint Preview ? Pin
desccode29-Sep-04 19:07
desccode29-Sep-04 19:07 
AnswerRe: Print Preview ? Pin
Jan van den Baard29-Sep-04 19:35
professionalJan van den Baard29-Sep-04 19:35 
GeneralNot compiling due to missing ado-stuff Pin
Christof Schardt23-Aug-04 9:38
Christof Schardt23-Aug-04 9:38 
GeneralRe: Not compiling due to missing ado-stuff Pin
Jan van den Baard23-Aug-04 19:40
professionalJan van den Baard23-Aug-04 19:40 
GeneralRe: Not compiling due to missing ado-stuff Pin
Christof Schardt24-Aug-04 20:43
Christof Schardt24-Aug-04 20:43 
GeneralRe: Not compiling due to missing ado-stuff Pin
gri27-Sep-04 9:23
gri27-Sep-04 9:23 
Generalclient area mouse event invalid Pin
10-Jun-04 13:00
suss10-Jun-04 13:00 
GeneralRe: client area mouse event invalid Pin
Jan van den Baard12-Jun-04 3:53
professionalJan van den Baard12-Jun-04 3:53 
GeneralRe: client area mouse event invalid Pin
Member 114028813-Jun-04 7:35
Member 114028813-Jun-04 7:35 
GeneralRe: client area mouse event invalid Pin
Jan van den Baard13-Jun-04 8:30
professionalJan van den Baard13-Jun-04 8:30 
GeneralLicense Pin
labuzov15-Jan-04 12:00
labuzov15-Jan-04 12:00 

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.