Click here to Skip to main content
13,048,584 members (79,574 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 11 Jun 2001

CAtlBitmapButton - ATL/WTL Ownerdraw Superclassed Bitmap Button

, 11 Jun 2001
Rate this:
Please Sign up or sign in to vote.
An owner drawn ATL/WTL bitmap button
<!-- Download Links -->


Recently, in one of my projects, I needed to build a simple user interface consisting of a series of bitmap buttons in a dialog. Something simple and probably easy to use. About the same time, I came across David Pizzolato's very nice article on skinned button at, that got me thinking. What came out of the whole endevour was CAtlBitmapButton - an ATL/WTL ownerdrawn superclassed bitmap button. The class is not really complete and represents work in progress. I'll be glad if any of you find this useful :-).

The CAtlBitmapButton class is very friendly and you can learn to use it in no time. The hardest part might be drawing the bitmaps (if you are as artistically challenged as I am !).

Now let's get down to the basics. We'll be building an ATL/WTL Dialog-based application so I assume you are slightly familiar with ATL/WTL and ATL Windowing.


How to use

To build the client, fire up Visual C++ and create a new Win32 application . Next we shall rig up ATL support to the project. Since we'd like to have ATL Wizard support, just follow the instructions step-by-step. If you already know how to do this, you can skip this part. First, in project's stdafx.h file, replace

#include &ltwindows.h>
#define RICHEDIT_VER 0x0100
#include &ltatlbase.h> 
extern CComModule _Module;
#include &ltatlcom.h> 
#include &ltatlwin.h>
#include &ltatlapp.h>
#include &ltatlctrls.h> 

Now add a new IDL file to the project that contains a blank library definition block like

library <Project Name>


Now, in the ClassView, right-click the IDL file you just added, and choose Settings. In the General tab of the project settings dialog, check the Exclude file from build option.

Next modify your projects .cpp file so that it looks like:

CComModule _Module;


int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
	// TODO: Place code here.
	_Module.Init(0, hInstance);
	return 0;

Having rigged up ATL/WTL support, goto Insert->New ATL Object. In the Miscellaneous category, choose Dialog and click on Next.Enter the short name as Dialog.

In the dialog resource, add 4 buttons(IDC_BUTTON1,IDC_BUTTON2,IDC_BUTTON3 and IDC_BUTTON4) and set the Ownerdraw properties of these buttons to true. You would also need to add a few bitmaps to the project such that each button has three state bitmaps (Selected, Down and Over).

Add the file, CAtlBitmapButton.h to the project. In ClassView, right click the dialog class and add four member variables of type CAtlBitmapButton to it like

CAtlBitmapButton m_button1,m_button2,m_button3,m_button4;

In the dialog's OnInitDialog(), add the following code :

m_button1.LoadStateBitmaps(IDB_LOADU, IDB_LOADD, IDB_LOAD);

m_button2.LoadStateBitmaps(IDB_PLAYU, IDB_PLAYD, IDB_PLAY);

m_button3.LoadStateBitmaps(IDB_SAVEU, IDB_SAVED, IDB_SAVE);

m_button4.LoadStateBitmaps(IDB_QUITU, IDB_QUITD, IDB_QUIT);

CAtlBitmapButton has a method LoadStateBitmaps() to load the state bitmaps. The last thing to do is to add the ATL macro REFLECT_NOTIFICATIONS() to the dialog's message map like:


Build the project and run it. Check that the buttons are displaying the correct state bitmap. To handle button-clicks. use ATL macro COMMAND_ID_HANDLER() in the message map as shown in above code for the OK and Cancel button. OnCancel looks like:

LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
	return 0;

That's it. Yippee!
Have fun.


David Pizzolato.


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


About the Author

Amit Dey
Web Developer
India India
Amit Dey is a freelance programmer from Bangalore,India. Chiefly programming VC++/MFC, ATL/COM and PocketPC and Palm platforms. Apart from programming and CP, he is a self-taught guitar and keyboard player.

He can be contacted at

You may also be interested in...

Comments and Discussions

GeneralNeed Help Pin
clement Lam20-Jan-06 5:06
memberclement Lam20-Jan-06 5:06 
QuestionWhy not use the CBitmapButton class? Pin
Claus20-Jun-01 22:13
memberClaus20-Jun-01 22:13 
In the AtlCtrlX.h you will find a CBitmapButton class, which is better than the MFC version, because you can use transparent bitmaps in your buttonSmile | :)

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 12 Jun 2001
Article Copyright 2001 by Amit Dey
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid