Click here to Skip to main content
11,411,263 members (64,185 online)
Click here to Skip to main content

Menu Bitmaps from Minimal Source Code

, 1 Feb 2002 CPOL
Rate this:
Please Sign up or sign in to vote.
Add bitmaps to your menus easily and with very little source code.

A menu with bitmaps


This article describes a method of adding bitmaps to your menus. The method is very easy to use, for example adding all the bitmaps on a tool bar is accomplished by a single function call. The demo project includes a class called BitmapMenu that can be used to add bitmap menus to your own projects. This class is made up of a small amount of source code, making it easy to understand and maintain.

There are two good related articles on the code project about adding bitmaps to menus. They are:

These are both excellent articles with lots of good accompanying code. Brent Corkum's code in particular produces nice looking bitmaps, and it has been extensively tested and updated. So of course you are thinking: "Why do I need to bother with your article?"

The main disadvantage of the Corkum method is the size of the code. Something as simple as placing bitmaps on menus requires a significant amount of code which must be maintained by you (or you have to hope that Mr. Corkum is nice enough to keep updating his classes). For this reason I chose to use the much more compact Denisov method. Nikolay Denisov's article addresses much more than putting bitmaps on menus, and the bitmap code is intertwined with his other code, so it is difficult to use independently. Therefore, I developed a class based on the Denisov method that is modular. The result is that both my method and the Corkum method are easy to setup, but there is a significant difference in the resulting amount of source code. The approximate lines of source code required by the two methods are:

  • Corkum method: 2,350 lines
  • This method: 250 lines

Unlike Corkum's work, this code has not been well tested. It has only been tested under Windows 98, and will not work under Windows 95/NT.

To use this code download the demo project. The demo has a second tool bar which demonstrates two of the class member functions: AddToolBar and RemoveToolBar. To add bitmap menus to your own project follow these 5 steps:

  1. Add the following files to your project:
    BitmapMenu.cpp, BitmapMenu.h, winuser2.h
  2. In MainFrm.h - Add this line to the top of the file:
    #include "BitmapMenu.h"
  3. In MainFrm.h - Inherit your main frame window from BitmapMenu rather than from CFrameWnd or CMDIFrameWnd.
    class CMainFrame : public BitmapMenu<CFrameWnd>
  4. In MainFrm.cpp - Add three message handlers between BEGIN_MESSAGE_MAP and END_MESSAGE_MAP.
  5. In MainFrm.cpp - At the end of the CMainFrame::OnCreate() function add each tool bar that you want to appear on the menu:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Warren Gardner

United States United States
No Biography provided

Comments and Discussions

QuestionWin32 SDK Example? Pinmemberajax197124-Jan-03 5:04 
AnswerRe: Win32 SDK Example? PinmemberWarren Gardner4-Feb-03 11:41 
GeneralRe: Win32 SDK Example? PinmemberTimWallace16-Jun-03 5:13 
GeneralRe: Win32 SDK Example? PinmemberHallsoft27-Aug-04 1:12 
GeneralChange checkmarks style Pinmembercaranthol17-Jan-03 7:51 
GeneralRe: Change checkmarks style PinmemberWarren Gardner4-Feb-03 11:35 
GeneralCompile error PinmemberLinas23-May-02 23:19 
GeneralRe: Compile error PinmemberWarren Gardner28-May-02 8:54 
Generalthe BitmapMenu project doesn't work Pinmembersohi4-May-02 5:50 
GeneralRe: the BitmapMenu project doesn't work PinmemberWarren Gardner15-May-02 9:28 
GeneralRe: the BitmapMenu project doesn't work Pinmembercaranthol2-Jan-03 1:44 
GeneralWhen the toolbar can be customized... Pinmemberwuwuli4-Apr-02 20:57 
GeneralRe: When the toolbar can be customized... PinmemberWarren Gardner10-Apr-02 5:26 
GeneralRe: When the toolbar can be customized... PinmemberSiuming11-Apr-02 0:45 
GeneralRe: When the toolbar can be customized... PinmemberWarren Gardner19-Apr-02 17:43 
QuestionIs there any way to show menu items with different colors and /or fonts? PinmemberGhasem Karimi26-Mar-02 3:15 
AnswerRe: Is there any way to show menu items with different colors and /or fonts? PinmemberWarren Gardner10-Apr-02 5:15 
GeneralA few problems PinmemberNeville Franks3-Feb-02 23:17 
GeneralRe: A few problems PinmemberWarren Gardner4-Feb-02 13:23 
GeneralRe: A few problems PinmemberNeville Franks6-Feb-02 2:24 
GeneralGood peace of code, but... PinmemberJean-Michel LE FOL3-Feb-02 7:54 
GeneralRe: Good peace of code, but... PinmemberWarren Gardner4-Feb-02 16:00 
GeneralRe: Good peace of code, but... PinmemberPierre C12-Feb-02 5:12 
GeneralAbout dialog. Pinmemberdsteuz2-Feb-02 19:24 
GeneralRe: About dialog. PinmemberWarren Gardner4-Feb-02 15:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150414.5 | Last Updated 2 Feb 2002
Article Copyright 2002 by Warren Gardner
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid