Click here to Skip to main content
Click here to Skip to main content

Cool Push Menu Button

, 3 Jul 2003
Rate this:
Please Sign up or sign in to vote.
This article shows the use of a Push button with a drop down menu, similar to the one found in the Office 2000 suite.

Sample Image - coolbtn.jpg


This article shows the use of a Push button with a drop down menu, similar to the one found in the Office 2000 suite. The code is encapsulated in a MFC class. The class itself is derived from a CButton class, by deriving from this class most of the button behavior is supplied.

The main core of the code is the drawing routine draw the button and its behavior. Also there is extensive use of mouse trapping code.

The public interface to access the class is shown here...

BOOL Create( LPCTSTR lpszCaption, DWORD dwStyle, 
                  const RECT& rect, CWnd* pParentWnd, UINT nID );
BOOL SetButtonImage(UINT nResourceId, COLORREF crMask);
BOOL AddMenuItem(UINT nMenuId,const CString strMenu, UINT nFlags);

These functions create the class, set the bitmap for the button and add menu items for the drop menu menu.

The bitmap must be added as a bitmap resource in the class and its probably best to use the standard toolbar button size (16x15 pixels).

The color reference for the mask is usually RGB(255,0,255) (Magenta).

Menu items are added to the menu button by the AddMenuItem function. You'll need to create a resource symbol and use the relevant menu flags found in the Windows API under menus (Beyond the scope of this document). Command handlers are then added to the parent windows message map (see the code example).

In the sample shown there the button is constructed in the OnInitDialog handler. The button is created as a Window, but could quite easy be changed to a subclassed dialog item.

There is room for improvement in the class; RemoveMenuItem, ModifyMenuItem could be added and the SetButtonImage could be modified to replace a current image, unfortunately project deadlines prevent me adding this functionality.


  • 29 July 2000 - updated source and demo
  • 4 July 2003 - update source and demo


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

Software Developer (Senior) Software Kinetics
United Kingdom United Kingdom

Software Kinetics
are experts in developing customised and bespoke applications and have expertise in the development of desktop, mobile and internet applications on Windows.

We specialise in:

  • User Interface Design
  • Desktop Development
  • Windows Phone Development
  • Windows Presentation Framework
  • Windows Forms
  • Windows Communication Framework
  • Windows Services
  • Network Applications
  • Database Applications
  • Web Development
  • Web Services
  • Silverlight
Visit Software Kinetics
Follow on   Twitter

Comments and Discussions

GeneralSmall Modification PinmemberChasCurry27-Jan-11 9:17 
GeneralMy vote of 4 PinmemberSmaaart5-Oct-10 20:14 
GeneralMy vote of 1 PinmemberSheetal_Joshi22-Oct-09 3:18 
GeneralRe: My vote of 1 PingroupNorm .net28-Oct-09 2:06 
GeneralRe: My vote of 1 PinmemberSheetal_Joshi8-Dec-09 6:48 
GeneralRe: My vote of 1 PingroupNorm .net8-Dec-09 21:44 
GeneralMy vote of 1 PinmemberRyleigh27-Mar-09 8:37 
GeneralRe: My vote of 1 PinmvpRajesh R Subramanian20-May-09 4:44 
GeneralRe: My vote of 1 PingroupNorm .net20-May-09 5:44 
GeneralMy vote of 1 PinmemberElkay9-Jan-09 7:37 
GeneralMislocation of the button PinmemberCarrie_Jia22-Jun-05 18:07 
GeneralMinor Modifications PinmemberDaemonNZ27-Nov-03 13:44 
GeneralA few additions... PinsussAnonymous7-Nov-03 7:21 
Question.NET Version for WindowsForms? PinsitebuilderUwe Keim25-Aug-03 1:10 
GeneralNew version PinmemberHans Dietrich7-Jul-03 3:19 
GeneralRe: New version PinmemberHans Dietrich7-Jul-03 5:38 
GeneralRe: New version PinmemberNormski17-Jul-03 22:16 
GeneralRe: New version PinmemberHans Dietrich18-Jul-03 8:45 
Generalnot descriptive!! PinmemberM.Shoaib Khan5-Jul-03 8:28 
GeneralRe: not descriptive!! PinmemberNormski17-Jul-03 7:47 
GeneralA better solution PinmemberSuha Aktan10-Jun-03 22:23 
GeneralRe: A better solution PinmemberCodeCracker11-Jun-03 10:30 
GeneralRe: A better solution PinmemberSuha Aktan12-Jun-03 4:25 
GeneralRe: A better solution PinmemberNormski16-Jun-03 9:34 
GeneralRe: A better solution Pinmemberveal14-Jun-03 3:58 
GeneralCCoolButton works with XP; additional features Pinmemberleighb10-Jun-03 15:07 
GeneralRe: CCoolButton works with XP; additional features PinmemberCodeCracker11-Jun-03 10:31 
QuestionDriven from keyboard? PinmemberCarl Young1-Apr-03 4:39 
Generalhelp desperately needed for Button menu.. Pinsuss*S*2-Feb-03 10:19 
Generalvery good Pinmemberyary19-Dec-02 2:31 
GeneralPossible improvement Pinmember__Stephane Rodriguez__16-Oct-02 6:13 
GeneralAnother small improvement PinsussCabbi28-Aug-02 22:58 
Generalhelp PinmemberAnonymous2-Jun-02 19:13 
Generalextra semicolon PinmemberAnonymous5-May-02 23:22 
GeneralRe: extra semicolon PinmemberNorm Almond16-May-02 12:12 
GeneralRe: Cool Push Menu Button Pinmembernkshastry200015-Feb-06 5:04 
GeneralRe: Cool Push Menu Button Pinmembernorm.net15-Feb-06 5:26 
GeneralRe: extra semicolon PinmemberShielsy104-Jul-03 8:57 
GeneralCan't seem to add bitmaps to submenus PinmemberJulia Larson26-Apr-02 11:46 
GeneralNevermind, I'm a knucklehead PinmemberJulia Larson26-Apr-02 12:19 
GeneralRe: Can't seem to add bitmaps to submenus PinmemberAnonymous31-May-02 0:52 
Generalenable/disable ,remove menu items Pinmemberamitbamzai11-Apr-02 19:26 
Generalenable/disable ,remove menu items Pinmemberamitbamzai11-Apr-02 19:23 
GeneralCommand not generated when the main button pressed PinmemberSimon Reeves18-Feb-02 3:59 
GeneralRe: Command not generated when the main button pressed PinmemberNorm Almond18-Feb-02 5:11 
GeneralRe: Command not generated when the main button pressed PinmemberNeville Franks3-Mar-02 22:05 
GeneralRe: Command not generated when the main button pressed PinmemberFlippant23-Apr-03 5:48 
GeneralBUG! The button is always drawn as a default button Pinmemberchcw6-Feb-02 14:39 
Generalneed splitbtn.h PinmemberAnonymous24-Oct-01 3:53 
GeneralRe: need splitbtn.h PinmemberGeorge17-Nov-01 11:31 

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.150326.1 | Last Updated 4 Jul 2003
Article Copyright 2000 by NormDroid
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid