Click here to Skip to main content
Click here to Skip to main content
Go to top

CMenuEx - Ownerdrawn Menu

, 27 Aug 2004
Rate this:
Please Sign up or sign in to vote.
An easy-to-use ownerdrawn menu, derived from CMenu.

Sample Image - CMenuEx.JPG

Introduction

This article introduces a CMenu-derived class for an owner drawn menu with customization available at runtime.

Background

The intention of this class is to provide an easy way of implementing custom menus with Office XP or Visual Studio .NET style.

All colors used in drawing the menu may be changed at runtime, and there is a variety of other settings provided for customizing the menu style.

Using the code

In order to use CMenuEx, you have to follow these steps:

  1. Include MenuEx.h and MenuEx.cpp in your project.
  2. Edit the header of the class handling the menu (usually MainFrm.h).
    #include "MenuEx/MenuEx.h"
    // ...
    DECLARE_MENUEX()
    // ...
    public:
        CMenuEx*    m_pMainMenu;
  3. Edit the source of the class handling the menu (usually MainFrm.cpp).
    IMPLEMENT_MENUEX(CMainFrame, CFrameWnd)
    // ...
    BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
        // ...
        ON_MENUEX_MESSAGES()    /* CMenuEx */
    END_MESSAGE_MAP()
    // ...
    CMainFrame::CMainFrame()
    {
        // ...
        m_pMainMenu = NULL;
    }
    // ...
    CMainFrame::~CMainFrame()
    {
        // ...
        delete m_pMainMenu;
    }
    // ...
    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
        // ...
        m_pMainMenu = new CMenuEx(this);
        if(m_pMainMenu->LoadMenu(IDR_MAINFRAME))
        {
            /*
                Custom color & size settings
                for startup should go here
            */
            ::DestroyMenu(m_hMenuDefault);
            SetMenu(m_pMainMenu);
            m_hMenuDefault = m_pMainMenu->GetSafeHmenu();
        }
        // ...
  4. If you want the menu to use the images of an existing toolbar, add the following code:
        if(m_pMainMenu->LoadMenu(IDR_MAINFRAME))
        {
            /*
                Custom color & size settings
                for startup should go here
            */
            m_pMainMenu->UseToolBarImages(&m_wndToolBar);    // Added line 
            ::DestroyMenu(m_hMenuDefault);
            SetMenu(m_pMainMenu);
            m_hMenuDefault = m_pMainMenu->GetSafeHmenu();
        }

    This sample code replaces the standard Main Menu of a SDI/MDI project with a CMenuEx, using the default settings of CMenuEx and the images of the default application toolbar.

Remarks

Menu icons and images are not yet supported. Also, it is not recommended to change the item size settings during runtime. Changing colors works fine though.

History

  • 08/28/2004 - Version 1.0.
  • 08/30/2004 - Version 1.1 (Added support for Images and Checkmarks).

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

C. Bügenburg
Web Developer
Germany Germany
I am from Germany and started working as a VC++ / MFC developer in 1996.
The company I am working for provides software for car workshops and sellers. Since I am working there, I developed one of their main products from scratch, first in VC++ 6, later porting it to VC++ 7.
Another part of my work is providing and maintaining various ASP and ASP.NET applications, the latter usually developed using C# and using a MS SQL Server as data provider.

Comments and Discussions

 
GeneralDynamically created Problem!~ [modified] Pinmemberangeltwb12345618-Aug-10 20:01 
GeneralDraw BackgroundColour of Top level Menu PinmemberAndiW13-Jun-05 5:36 
GeneralRe: Draw BackgroundColour of Top level Menu PinmemberDevil for ever9-Jun-06 8:34 
Questionhow to change font Pinmembermuharrem8-Dec-04 23:01 
GeneralProblem PinmemberDavid Simmonds12-Nov-04 6:42 
QuestionCan you upload source code? PinsussAnonymous19-Oct-04 4:36 
AnswerRe: Can you upload source code? PinmemberC. Bügenburg19-Oct-04 5:02 

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 | Mobile
Web04 | 2.8.140916.1 | Last Updated 28 Aug 2004
Article Copyright 2004 by C. Bügenburg
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid