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.

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:

Under the menu Tools->Options...

Select VC++ Directories under the Projects item in the tree view.

Select Include files in the Show directories for combo box.

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.

Select Library files in the Show directories for combo box.

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.

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.

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.

Share

About the Author

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.

I'm getting a compiler error when it tries to compile the _NO_CLASS(x) defines. They look pretty straightforward, but the compiler doesn't like them for some reason?

I'm using the VC++ 2005 Express (the freebie) with the PSDK installed. Is that the problem? Should I just shell out the $$ for the real compiler?

No. You do not need to pay for another compiler because the Express compiler is as good as the compiler in any other VS 2005 product (as far as I know it's the same compiler). I know there are some issues compiling ClassLib under VS2k5.

I will look into what needs to be changed in order to compile it using VS2k5. Gimme a few days...

great job - I think! I'd like to try out your library in VC++, but you say that it is not supported in version 2.9 and forward. Is it possible to get a hold of an older version?

Support for VC++ 6, which I presume you are talking about, has indeed stopped. However it should be possible to create a VC6 project and compile the library providing you have a recent platfrom SDK. The only thing I can think of which may cause some trouble is the the ADO support in the library.

I'm sorry but there is no out-of-the box VC6 version available anymore.

I tried to seperate my program into more parts/DLL's that I don't have to update everything when I change something. The problem is that ClassLib does not work in DLL's ... the only way I found was to create/draw all controls which are in DLL's by old WinApi-Style

The rest: I've added functions like button.Connect(WM_LBUTTONDOWN, window, window::callback) and window.ConnectCommand(IDOK ..) to my derived class because I dont't like this windowproc() things ... maybe this would be a idea for next versions (makes button handling much prettier)

gri wrote:The rest: I've added functions like button.Connect(WM_LBUTTONDOWN, window, window::callback) and window.ConnectCommand(IDOK ..) to my derived class because I dont't like this windowproc() things ... maybe this would be a idea for next versions (makes button handling much prettier)

The version on CodeProject now defines a set of macros in Classes/Windows/Window.h which do some message cracking for you. You can take a look at the CustomTabCtrl source for an example on how to use them. They still generate a WindowProc() with a switch...case statement but they can make your life a little bit easier.

I wish to thank all the programmers that contributed to this and similar libraries. I am not a "Guru" in Visual C++ programming, but this library made my life - simply put - a walk in the park. Thanks again guys. Great work.