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

     
    GeneralRe: PopUP Menu Pin
    FPF28-Jan-04 1:59
    FPF28-Jan-04 1:59 
    GeneralRe: PopUP Menu Pin
    suvi_rahul16-Mar-04 22:51
    suvi_rahul16-Mar-04 22:51 
    GeneralRe: PopUP Menu Pin
    Jean-Michel LE FOL17-Mar-04 5:04
    Jean-Michel LE FOL17-Mar-04 5:04 
    GeneralRe: PopUP Menu Pin
    suvi_rahul17-Mar-04 22:35
    suvi_rahul17-Mar-04 22:35 
    GeneralRe: PopUP Menu Pin
    Jean-Michel LE FOL18-Mar-04 21:27
    Jean-Michel LE FOL18-Mar-04 21:27 
    QuestionWhere are the triangles drawn for submenus? Pin
    tom_olinger10-Dec-03 17:18
    tom_olinger10-Dec-03 17:18 
    AnswerRe: Where are the triangles drawn for submenus? Pin
    fjlaga_old18-Mar-04 10:12
    fjlaga_old18-Mar-04 10:12 
    AnswerRe: Where are the triangles drawn for submenus? Pin
    scroll_lock15-Jun-05 14:46
    sussscroll_lock15-Jun-05 14:46 
    QuestionHow to modify states of menu items Pin
    Member 3813138-Dec-03 23:06
    Member 3813138-Dec-03 23:06 
    GeneralMenu option being left on screen after menu selection on Win2K Pin
    hound2-Dec-03 10:06
    hound2-Dec-03 10:06 
    GeneralCheckBox and RadioButton Pin
    |3uRT0n2516-Nov-03 8:57
    |3uRT0n2516-Nov-03 8:57 
    GeneralBlue box highlighting in Menu Pin
    riniaustin14-Nov-03 11:08
    riniaustin14-Nov-03 11:08 
    GeneralRe: Blue box highlighting in Menu Pin
    Ken Hester15-Dec-03 10:51
    Ken Hester15-Dec-03 10:51 
    GeneralRe: Blue box highlighting in Menu Pin
    Danushka15-Dec-03 18:49
    Danushka15-Dec-03 18:49 
    GeneralRe: Blue box highlighting in Menu Pin
    Ken Hester16-Dec-03 4:31
    Ken Hester16-Dec-03 4:31 
    GeneralRe: Blue box highlighting in Menu Pin
    Danushka16-Dec-03 19:33
    Danushka16-Dec-03 19:33 
    GeneralMenuXP causes several problems Pin
    Osborn10-Nov-03 23:59
    Osborn10-Nov-03 23:59 
    GeneralCrash with GetLBText and MenuXP Hook Pin
    jbierling_21-Oct-03 9:05
    jbierling_21-Oct-03 9:05 
    GeneralRe: Crash with GetLBText and MenuXP Hook Pin
    jbierling_6-Nov-03 8:11
    jbierling_6-Nov-03 8:11 
    GeneralA couple of improvements Pin
    crappy_sites16-Oct-03 16:39
    crappy_sites16-Oct-03 16:39 
    GeneralRe: A couple of improvements Pin
    jung-kreidler16-Oct-03 20:05
    jung-kreidler16-Oct-03 20:05 
    GeneralRe: A couple of improvements Pin
    Larry R.9-Jan-04 13:31
    Larry R.9-Jan-04 13:31 
    GeneralToolbar button Pin
    jung-kreidler16-Oct-03 5:23
    jung-kreidler16-Oct-03 5:23 
    GeneralRe: Toolbar button Pin
    Jean-Michel LE FOL16-Oct-03 8:36
    Jean-Michel LE FOL16-Oct-03 8:36 
    GeneralRe: Toolbar button Pin
    jung-kreidler16-Oct-03 20:03
    jung-kreidler16-Oct-03 20:03 

    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.