Click here to Skip to main content
13,291,254 members (60,073 online)
Click here to Skip to main content
Add your own
alternative version


13 bookmarked
Posted 24 Nov 2007

Add icons to standard menus in WindowsXP and Windows Vista

, 24 Nov 2007
Rate this:
Please Sign up or sign in to vote.
Add icons to standard menus in WindowsXP and Windows Vista
Screenshot - MenuIcon1.png Screenshot - MenuIcon2.png


This project simplifies the use of icons in menus in WindowsXP and Windows Vista C++ projects. The project consist of a small class called 'CMenuIcon' which can be incorporated quickly in any Windows C++ project.


There a lot of examples on the Internet of how icons can be added to menus. However, most example are based on ownerdrawn menus. The disadvantage of this approach is that with every new version of Windows the style of the menus will look outdated quickly. Also for a small application a class for an ownerdrawn menu is a bit overkill. These were my reasons to search for an easy-to-use method with a small code base.

I found on the internet two examples which could do that, however these examples were WindowsXP or Windows Vista only. My class 'CMenuIcon' combines these to examples into one class.

Using the code

The class can be incorporated in three steps into your C++ project.

The first step is to create an instance of the CMenuIcon class and add combinations of a command-id and a icon (bitmap). This can be done in the initialisation steps of your application. It is advised to use only one instance of the CMenuIcon class, so you have global combinations of commands and icons.

//Create an instance of the CMenuIcon class
oMenuIcon = new CMenuIcon(hInstance);

//Add the icon-command combinations
oMenuIcon->AddMenuCommandIcon(ID_FILE_NEW, IDB_NEW, RGB(255,0,255));
oMenuIcon->AddMenuCommandIcon(ID_FILE_OPEN, IDB_OPEN, RGB(255,0,255));
oMenuIcon->AddMenuCommandIcon(ID_FILE_SAVE, IDB_SAVE, RGB(255,0,255));

The second step is processing the menu. The menu has to be processed because the icons has to be associated with it. You don't have to make any changes to your menu resources. The class will handle this.

//Process the menu
hCurrentMenu = GetMenu(hWnd);

The final step is an addition to your WndProc.

//This is an addition for ownerdrawing icons in WindowsXP
if (oMenuIcon->WndProc(hWnd, message, wParam, lParam, iReturn)) return iReturn;

Points of Interest

See this class as a proof-of-concept. There are a lot of possible enhancement. For instance; my class uses GDI+ to convert an RGB bitmap to a ARGB bitmap to be used in Windows Vista. This can be done a lot quicker and certainly cleaner.


Version 1.0: Initial release.


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

Netherlands Netherlands
I am a developing software as a hobby for over 10 years now. The focus have been on imaging applications and card games.

You may also be interested in...

Comments and Discussions

GeneralVista transparency issue Pin
Pacestar Coder8-Dec-07 12:42
memberPacestar Coder8-Dec-07 12:42 
GeneralThanks, great code. Pin
donald1284-Dec-07 23:36
memberdonald1284-Dec-07 23:36 

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.171207.1 | Last Updated 24 Nov 2007
Article Copyright 2007 by rjlmmaas
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid