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

     
    QuestionPopup it as system tray menu with flat style? Pin
    iProgram (WangYue)28-Jun-03 20:13
    iProgram (WangYue)28-Jun-03 20:13 
    AnswerRe: Popup it as system tray menu with flat style? Pin
    Jean-Michel LE FOL29-Jun-03 5:44
    Jean-Michel LE FOL29-Jun-03 5:44 
    QuestionMmm, it's not doing anything, what am I missing? Pin
    vtecman20-Jun-03 6:35
    vtecman20-Jun-03 6:35 
    AnswerRe: Mmm, it's not doing anything, what am I missing? Pin
    ZeroPageX24-Aug-03 18:33
    ZeroPageX24-Aug-03 18:33 
    GeneralThanks, but still isn't working Pin
    vtecman25-Aug-03 1:04
    vtecman25-Aug-03 1:04 
    GeneralRe: Thanks, but still isn't working Pin
    ZeroPageX25-Aug-03 4:19
    ZeroPageX25-Aug-03 4:19 
    QuestionWhat about .Net?? Pin
    Member 43645312-Jun-03 16:21
    Member 43645312-Jun-03 16:21 
    AnswerRe: What about .Net?? Pin
    Jean-Michel LE FOL14-Jun-03 22:11
    Jean-Michel LE FOL14-Jun-03 22:11 
    The .Net Solution file contains three VC7 projects.
    The CMenuXP class is compatible with VC6 and VC7.
    GeneralRe: What about .Net?? Pin
    Member 43645315-Jun-03 15:37
    Member 43645315-Jun-03 15:37 
    GeneralRe: What about .Net?? .NetMagic!!!!! Pin
    ideras14-Jul-03 8:42
    ideras14-Jul-03 8:42 
    Questionwhat about a office2003 stoolbar ? Pin
    schaereran@gmx.net5-Jun-03 23:42
    schaereran@gmx.net5-Jun-03 23:42 
    GeneralXP Menu in ATL Composite control Pin
    Schauhan1-Jun-03 19:56
    Schauhan1-Jun-03 19:56 
    Questionbug? Pin
    zhou_wz1-Jun-03 17:42
    zhou_wz1-Jun-03 17:42 
    AnswerRe: bug? Pin
    zhou_wz1-Jun-03 23:05
    zhou_wz1-Jun-03 23:05 
    AnswerRe: bug? Pin
    zhou_wz1-Jun-03 23:15
    zhou_wz1-Jun-03 23:15 
    GeneralProblem Pin
    grangregpgran1-Jun-03 1:58
    grangregpgran1-Jun-03 1:58 
    GeneralRe: Problem Pin
    TeleStar1-Jun-03 11:16
    TeleStar1-Jun-03 11:16 
    GeneralRe: Problem Pin
    grangregpgran2-Jun-03 3:46
    grangregpgran2-Jun-03 3:46 
    GeneralHeading in the menu bar is not blue Pin
    Alex Evans6-Jul-03 16:11
    Alex Evans6-Jul-03 16:11 
    GeneralXP Pin
    Jan van den Baard31-May-03 21:39
    professionalJan van den Baard31-May-03 21:39 
    Questionupdated WTL port? Pin
    MasterMav28-May-03 13:21
    MasterMav28-May-03 13:21 
    Generaldialog please example Pin
    Haitham Khedre22-May-03 6:33
    Haitham Khedre22-May-03 6:33 
    QuestionSystem Menu ?? Pin
    Park KeunHyun13-May-03 19:47
    Park KeunHyun13-May-03 19:47 
    Generalother litter bug. Pin
    Weishou8-May-03 4:31
    Weishou8-May-03 4:31 
    GeneralCMenuXP::SetXPLookNFeel (this); Pin
    Weishou8-May-03 3:36
    Weishou8-May-03 3:36 

    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.