Click here to Skip to main content
15,890,897 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

     
    GeneralTrackPopupMenu doesn't work Pin
    Jaime Stuardo8-Apr-03 16:10
    Jaime Stuardo8-Apr-03 16:10 
    GeneralRe: TrackPopupMenu doesn't work Pin
    Jean-Michel LE FOL9-Apr-03 0:21
    Jean-Michel LE FOL9-Apr-03 0:21 
    GeneralRe: TrackPopupMenu doesn't work Pin
    Jaime Stuardo9-Apr-03 14:19
    Jaime Stuardo9-Apr-03 14:19 
    Questionoffice 2003-style toolbar?? Pin
    schaereran@gmx.net6-Apr-03 22:22
    schaereran@gmx.net6-Apr-03 22:22 
    Questionwhy I can't work ? Pin
    cupid008f4-lu5-Apr-03 22:22
    cupid008f4-lu5-Apr-03 22:22 
    AnswerRe: why I can't work ? Pin
    Jean-Michel LE FOL6-Apr-03 22:47
    Jean-Michel LE FOL6-Apr-03 22:47 
    GeneralCMenuXP::UpdateMenuBar Pin
    Reverend EvvL X4-Apr-03 10:40
    Reverend EvvL X4-Apr-03 10:40 
    QuestionHow do I add ON_MENUXP_MESSAGES() Pin
    Corrupt Sektor29-Mar-03 3:12
    Corrupt Sektor29-Mar-03 3:12 
    Hi,

    What message do I add in order for the macro ON_MENUXP_MESSAGES() to be created in the BEGIN MESSAGE MAP
    ...END MESSAGE MAP section?

    If I add it in manually, the code run, but I can't view the CMainFrm class using ClassWizard.

    What am I missing?
    AnswerRe: How do I add ON_MENUXP_MESSAGES() Pin
    Anonymous1-Apr-03 2:53
    Anonymous1-Apr-03 2:53 
    GeneralMenu Bitmaps Pin
    johnyboy13-Mar-03 7:25
    johnyboy13-Mar-03 7:25 
    GeneralRe: Menu Bitmaps Pin
    Jean-Michel LE FOL13-Mar-03 10:58
    Jean-Michel LE FOL13-Mar-03 10:58 
    GeneralI have a question Pin
    Seungju Choi7-Mar-03 1:44
    Seungju Choi7-Mar-03 1:44 
    Generaldon't forget it!! Pin
    C·o·Y·o·T·e6-Mar-03 11:33
    C·o·Y·o·T·e6-Mar-03 11:33 
    Generaldoesn't work for dialog based app Pin
    tao tao26-Feb-03 17:05
    tao tao26-Feb-03 17:05 
    GeneralRe: doesn't work for dialog based app Pin
    SanjiDeluxe12-Mar-03 8:52
    SanjiDeluxe12-Mar-03 8:52 
    GeneralRe: doesn't work for dialog based app Pin
    Anonymous12-Mar-03 16:34
    Anonymous12-Mar-03 16:34 
    Generaldouble shadow under Windows XP Pin
    trulyjacky25-Feb-03 16:48
    trulyjacky25-Feb-03 16:48 
    GeneralRe: double shadow under Windows XP Pin
    Jean-Michel LE FOL26-Feb-03 7:42
    Jean-Michel LE FOL26-Feb-03 7:42 
    GeneralQuestion Pin
    viron7521-Feb-03 10:15
    viron7521-Feb-03 10:15 
    GeneralRe: Question Pin
    Jean-Michel LE FOL22-Feb-03 18:44
    Jean-Michel LE FOL22-Feb-03 18:44 
    GeneralRe: Question Pin
    viron7526-Feb-03 13:02
    viron7526-Feb-03 13:02 
    QuestionHow to use it in VB.Net Pin
    vaidy19-Feb-03 3:26
    vaidy19-Feb-03 3:26 
    GeneralProgram fails with ON_MENUXP_MESSAGES() in CMainFrame Pin
    darthmaul16-Feb-03 21:56
    darthmaul16-Feb-03 21:56 
    GeneralRe: corrected ! Pin
    darthmaul17-Feb-03 23:03
    darthmaul17-Feb-03 23:03 
    QuestionWhat about toolbar ? Pin
    darthmaul12-Feb-03 2:45
    darthmaul12-Feb-03 2:45 

    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.