Click here to Skip to main content
15,885,905 members
Articles / Web Development / HTML

CMenuEX - A Bitmap Menu Class

Rate me:
Please Sign up or sign in to vote.
2.40/5 (8 votes)
4 Jan 2001 151.1K   1.6K   35   20
Implementing an Ownerdrawn menu

Sample Image - MenuEx1.gif Image 2

Introduction

MS Visual Studio and MS Office products have menus with bitmaps next to commands which are associated with toolbar buttons. The aim of this class was to provide a quick and easy method of implementing these types of menus. The menu class can be used to replace the mainframe window menu as well being used as a context menu.

Implementation

Files

  • ToolBarWrapper.h & ToolBarWrapper.cpp (Toolbar resource wrapper)
  • MenuEx.h & MenuEx.cpp (principle Menu class)

Add the above files to your project.

Next add the view header file to your projects header file where the menu is to be used for instance Mainfrm.h.

C++
#include "MenuEx.h"

CMenuEx is the class to be included to implement the menu.

C++
class CMainFrame : public CFrameWnd
{
 ... Some other code
 CMenuEx m_menu; 
};

To initialise the menu for a frame window, call CMenuEx::Initialize in the OnCreate procedure.

C++
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
  if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
    return -1;

// MENUEX_ADD - Mainframe menu is initialized with parent window
  if (!m_menu.Initialize(IDR_MAINFRAME,this))
    return -1;

 ... Some other code

We now need to provide support for sizing and drawing the menu, that requires processing the WM_MEASUREITEM and WM_DRAWITEM messages. Use the class wizard to create the message handlers (Note: You change the message filter option in the class wizard to Window).

Menu items which use the Radio feature in MFC require this adding to your project where the SetRadio option is used to update the command user interface.

C++
// Example message handle for radio buttons
void CMainFrame::OnUpdateRadioItem3(CCmdUI* pCmdUI)
{

  pCmdUI->SetRadio(m_nRadioGroup == 3);
  m_menu.SetRadio(pCmdUI,m_nRadioGroup == 3); // Set radio button here
}

That's it! The next versions will support the intelligent menus and the new fangled MS Visual Studio 7.0beta menus.

License

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.


Written By
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
  • ASP.net


Visit Software Kinetics

Comments and Discussions

 
QuestionGood but how to support multiple toolbars ? Pin
zhonglin.liang23-Aug-06 16:28
zhonglin.liang23-Aug-06 16:28 
QuestionHow to response the click of menu?? Pin
joynet28-Jul-04 22:38
joynet28-Jul-04 22:38 
GeneralWhy Can't work in MDI Main Menu Pin
qyq0011-Sep-03 18:32
qyq0011-Sep-03 18:32 
GeneralMemory Leak Pin
Wolfram Steinke22-Mar-02 17:32
Wolfram Steinke22-Mar-02 17:32 
GeneralProblem in ShortKey text Pin
Mehul4-Mar-02 22:05
Mehul4-Mar-02 22:05 
GeneralCoolMenu and outer calls Pin
10-Feb-02 19:33
suss10-Feb-02 19:33 
GeneralRemake CmenuEx Pin
13-Jan-02 23:12
suss13-Jan-02 23:12 
GeneralDisabling the menu Pin
9-Nov-01 9:38
suss9-Nov-01 9:38 
GeneralBug when loading popup submenus with certain amount of items Pin
18-Oct-01 21:05
suss18-Oct-01 21:05 
QuestionBitmap Menu for Dialog Apps?? Pin
18-Oct-01 3:43
suss18-Oct-01 3:43 
General"good but" Pin
peterchen17-Aug-01 1:23
peterchen17-Aug-01 1:23 
GeneralRe: "good but" Pin
NormDroid18-Sep-01 22:23
professionalNormDroid18-Sep-01 22:23 
GeneralRe: "good but" Pin
peterchen19-Sep-01 0:10
peterchen19-Sep-01 0:10 
GeneralBug.. Pin
Franc Milan21-Feb-01 1:16
Franc Milan21-Feb-01 1:16 
GeneralChange Font Pin
Susanne Schmidt-Ott23-Jan-01 1:05
Susanne Schmidt-Ott23-Jan-01 1:05 
How do I change the font of the menu? As I see in the example screen shot "Trebuchet MS" is used, which is not the default setting.
QuestionSupport for single menu/multiple toolbars? Pin
8-Jan-01 1:14
suss8-Jan-01 1:14 
GeneralGiving Error Pin
8-Jan-01 0:03
suss8-Jan-01 0:03 
GeneralRe: Giving Error Pin
WREY7-Jan-04 19:16
WREY7-Jan-04 19:16 
QuestionWhere's your homepage? Pin
7-Jan-01 16:07
suss7-Jan-01 16:07 
AnswerRe: Where's your homepage? Pin
8-Jan-01 4:50
suss8-Jan-01 4:50 

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.