Click here to Skip to main content
Licence 
First Posted 4 Jan 2001
Views 120,494
Bookmarked 32 times

CMenuEX - A bitmap menu class

By | 4 Jan 2001 | Article
Implementing an Ownerdrawn menu
  • Download demo project - 35 Kb
  • Sample Image - MenuEx1.gif  

    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

    About the Author

    Norm .net

    Chief Technology Officer
    Software Kinetics
    United Kingdom United Kingdom

    Member

    Follow on Twitter Follow on Twitter



    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

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    QuestionGood but how to support multiple toolbars ? PinmemberLZL101016:28 23 Aug '06  
    QuestionHow to response the click of menu?? Pinmemberjoynet22:38 28 Jul '04  
    GeneralWhy Can't work in MDI Main Menu Pinmemberqyq00118:32 1 Sep '03  
    GeneralMemory Leak PinmemberWolfram Steinke17:32 22 Mar '02  
    GeneralProblem in ShortKey text PinmemberMehul22:05 4 Mar '02  
    GeneralCoolMenu and outer calls PinmemberAnonymous19:33 10 Feb '02  
    GeneralRemake CmenuEx PinmemberGennady Knoll23:12 13 Jan '02  
    GeneralDisabling the menu PinmemberJames Bleakney9:38 9 Nov '01  
    GeneralBug when loading popup submenus with certain amount of items PinmemberZdenek Breitenbacher21:05 18 Oct '01  
    QuestionBitmap Menu for Dialog Apps?? PinmemberJames Bleakney3:43 18 Oct '01  
    General"good but" Pinmemberpeterchen1:23 17 Aug '01  
    GeneralRe: "good but" PinmemberNorm Almond22:23 18 Sep '01  
    GeneralRe: "good but" Pinmemberpeterchen0:10 19 Sep '01  
    GeneralBug.. PinmemberFranc Milan1:16 21 Feb '01  
    GeneralChange Font PinmemberSusanne Schmidt-Ott1:05 23 Jan '01  
    QuestionSupport for single menu/multiple toolbars? PinmemberCraig Henderson1:14 8 Jan '01  
    GeneralGiving Error PinmemberAnonymous0:03 8 Jan '01  
    GeneralRe: Giving Error PinmemberWREY19:16 7 Jan '04  
    QuestionWhere's your homepage? PinmemberDandy Cheung16:07 7 Jan '01  
    AnswerRe: Where's your homepage? PinmemberBrett Kapilik4:50 8 Jan '01  

    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.

    Permalink | Advertise | Privacy | Mobile
    Web04 | 2.5.120517.1 | Last Updated 5 Jan 2001
    Article Copyright 2001 by Norm .net
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid