Click here to Skip to main content
15,867,756 members
Articles / Desktop Programming / MFC
Article

CMenuXP - The Office XP Style Menu

Rate me:
Please Sign up or sign in to vote.
4.94/5 (114 votes)
13 Jul 2003CPOL2 min read 1.3M   27.9K   242   342
Owner drawn menu with the Office XP visual style

Sample Image - MenuXP.gif

Menus in dialog windows : Sample Image (Menus in Dialog Window)- MenuXP_dlg.gif

Introduction

This article presents an implementation of an owner drawn menu with the Office XP and Visual Studio .NET visual style.

Using the code

To use the CMenuXP class in your projects, you have to add 3 macros in your code:

  1. In the header file of the class that handles the menu (probably the MainFrame):
    #include "Tools/MenuXP.h"    // Before the declaration of the class
    // ...
    
    DECLARE_MENUXP()             // Into the definition of the class
  2. In the source file of the same class:
    IMPLEMENT_MENUXP(className, baseClass);
  3. In the message map of the class:
    BEGIN_MESSAGE_MAP(className, baseClass)
        // ...
        ON_MENUXP_MESSAGES()   // <-- Added line
    END_MESSAGE_MAP()

To make borders flat, I subclass the popup menu window managed by the system. To make it possible, you have to add those 2 calls in your code:

  1. In the InitInstance method of your CWinApp derived class:
    CMenuXP::InitializeHook();
  2. In the ExitInstance method of your CWinApp derived class:
    CMenuXP::UninitializeHook();

To make the menubar flat, you must do this call:

CMenuXP::UpdateMenuBar (pFrameWnd); // pFrameWnd refers to the frame that 
                                    // contains the MenuBar

The best place for this call depends of the frame type:

  • For MDI application, into the OnUpdateFrameMenu method of the child windows.
  • For SDI application, into the LoadFrame method of the main frame.

Finally, don't forget the last call:

CMenuXP::SetXPLookNFeel (pFrameWnd); // refers to the frame that contains 
                                     // the MenuBar

Without this call, menus will appear in a standard mode.

    To draw the menu items, I reused some classes already presented in my article: Office XP look & feel.

    History

    • 02/08/2002 - First release.
    • 01/06/2003 - Adding flat borders and flat menubar.
    • 05/31/2003 - Kris Wojtas has updated the source code to allow MenuXP to draw "radio", "check" state and gradient under bitmaps.
    • 06/02/2003 - Corrections, radio items support (thanks to Kris Wojtas) and new demos (flat controls and dialog based sample). You can get the latest update to this article at www.azsoft.free.fr.
    • 14 Jul 03 - further update by Kris:

      Sample Image

    License

    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


    Written By
    Web Developer CSC
    France France
    Jean-Michel LE FOL is a GraphTalk product architect.
    GraphTalk is a set of products which cover the whole scope of the development process. GraphTalk is used by the main insurance compagnies over the world.
    The development team is currently based in France near Paris.

    Comments and Discussions

     
    GeneralProblem: disabled / grayed menu items appear enabled Pin
    Ronen Babayoff16-Oct-04 2:38
    Ronen Babayoff16-Oct-04 2:38 
    GeneralRe: Problem: disabled / grayed menu items appear enabled Pin
    Member 101913217-Mar-05 23:28
    Member 101913217-Mar-05 23:28 
    GeneralRe: Problem: disabled / grayed menu items appear enabled Pin
    alex_ger24-May-05 13:42
    alex_ger24-May-05 13:42 
    GeneralCMenuXP::OnMeasureItem Question Pin
    fjlaga30-Sep-04 22:23
    fjlaga30-Sep-04 22:23 
    Generalcontext menu on windows shelf Pin
    mickelliot3-Sep-04 15:42
    mickelliot3-Sep-04 15:42 
    Questionhow to get default system menu Pin
    wangxin_china17-Jul-04 6:32
    wangxin_china17-Jul-04 6:32 
    QuestionCan't we apply image to menu with updated XP menu files??? Pin
    Jigar Mehta24-Jun-04 2:49
    Jigar Mehta24-Jun-04 2:49 
    AnswerRe: Can't we apply image to menu with updated XP menu files??? Pin
    Jigar Mehta17-Nov-04 21:33
    Jigar Mehta17-Nov-04 21:33 
    Yes,
    The problem solved, Actually the problem I made was I took Imagelist member a local member of the class and not the class's member variable.. When I took it as class's member variable, it worked fine...

    Rose | [Rose]

    Jigar Mehta
    (jigarmehta@gatescorp.com)

    Software Developer
    Gates Information Systems
    India
    AnswerRe: Can't we apply image to menu with updated XP menu files??? Pin
    Jigar Mehta17-Nov-04 21:33
    Jigar Mehta17-Nov-04 21:33 
    GeneralColouring the MENU BAR Pin
    Alex Evans20-Jun-04 22:15
    Alex Evans20-Jun-04 22:15 
    GeneralColouring the MENU BAR Pin
    Alex Evans20-Jun-04 22:04
    Alex Evans20-Jun-04 22:04 
    GeneralAuthorize Pin
    Kenan Hrustanovic12-Jun-04 4:53
    Kenan Hrustanovic12-Jun-04 4:53 
    GeneralLicensing?! Pin
    ge99819211-Jun-04 16:27
    ge99819211-Jun-04 16:27 
    GeneralThank you for your compliments! Pin
    Jean-Michel LE FOL11-Jun-04 18:51
    Jean-Michel LE FOL11-Jun-04 18:51 
    GeneralRe: Thank you for your compliments! Pin
    Lee Bamford17-Dec-04 3:38
    Lee Bamford17-Dec-04 3:38 
    GeneralMenuXP with MFC in a shared vs static Library Pin
    Vivian De Smedt1-Jun-04 2:18
    Vivian De Smedt1-Jun-04 2:18 
    QuestionWhat is the problem? Pin
    MangoBoy27-May-04 22:15
    MangoBoy27-May-04 22:15 
    GeneralBug Report Pin
    miracle_chen20-May-04 3:20
    miracle_chen20-May-04 3:20 
    GeneralRe: Bug Report Pin
    http97428-May-05 7:52
    http97428-May-05 7:52 
    GeneralRe: Bug Report Pin
    http97428-May-05 20:40
    http97428-May-05 20:40 
    GeneralRe: Bug Report Pin
    Rui Frazao10-Sep-12 12:59
    Rui Frazao10-Sep-12 12:59 
    GeneralBug report Pin
    retinex26-Apr-04 19:43
    retinex26-Apr-04 19:43 
    GeneralRe: Bug report Pin
    badger23025-May-04 10:42
    badger23025-May-04 10:42 
    GeneralRe: Bug report Pin
    tezzz16-Jun-04 20:16
    tezzz16-Jun-04 20:16 
    GeneralRe: Bug report Pin
    xtmono14-Oct-04 21:37
    xtmono14-Oct-04 21:37 

    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.