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

CMenuEX - A bitmap menu class

, 4 Jan 2001
Rate this:
Please Sign up or sign in to vote.
Implementing an Ownerdrawn menu
<!-- Download Links -->
  • Download demo project - 35 Kb
  • <!-- Article image -->

    Sample Image - MenuEx1.gif  

    <!-- Main HTML starts here -->

    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.

    Implemention

    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

    #include "MenuEx.h"

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

    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.

    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, the 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).

    For 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.

    // 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

    Share

    About the Author

    NormDroid
    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
    Follow on   Twitter

    Comments and Discussions

     
    QuestionGood but how to support multiple toolbars ? PinmemberLZL101023-Aug-06 17:28 
    QuestionHow to response the click of menu?? Pinmemberjoynet28-Jul-04 23:38 
    GeneralWhy Can't work in MDI Main Menu Pinmemberqyq0011-Sep-03 19:32 
    GeneralMemory Leak PinmemberWolfram Steinke22-Mar-02 18:32 
    GeneralProblem in ShortKey text PinmemberMehul4-Mar-02 23:05 
    GeneralCoolMenu and outer calls PinmemberAnonymous10-Feb-02 20:33 
    GeneralRemake CmenuEx PinmemberGennady Knoll14-Jan-02 0:12 
    GeneralDisabling the menu PinmemberJames Bleakney9-Nov-01 10:38 
    GeneralBug when loading popup submenus with certain amount of items PinmemberZdenek Breitenbacher18-Oct-01 22:05 
    QuestionBitmap Menu for Dialog Apps?? PinmemberJames Bleakney18-Oct-01 4:43 
    General"good but" Pinmemberpeterchen17-Aug-01 2:23 
    GeneralRe: "good but" PinmemberNorm Almond18-Sep-01 23:23 
    GeneralRe: "good but" Pinmemberpeterchen19-Sep-01 1:10 
    GeneralBug.. PinmemberFranc Milan21-Feb-01 2:16 
    GeneralChange Font PinmemberSusanne Schmidt-Ott23-Jan-01 2:05 
    QuestionSupport for single menu/multiple toolbars? PinmemberCraig Henderson8-Jan-01 2:14 
    GeneralGiving Error PinmemberAnonymous8-Jan-01 1:03 
    GeneralRe: Giving Error PinmemberWREY7-Jan-04 20:16 
    QuestionWhere's your homepage? PinmemberDandy Cheung7-Jan-01 17:07 
    AnswerRe: Where's your homepage? PinmemberBrett Kapilik8-Jan-01 5:50 

    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
    Web04 | 2.8.141223.1 | Last Updated 5 Jan 2001
    Article Copyright 2001 by NormDroid
    Everything else Copyright © CodeProject, 1999-2014
    Layout: fixed | fluid