Click here to Skip to main content
Licence CPOL
First Posted 7 Feb 2002
Views 618,361
Downloads 22,623
Bookmarked 233 times

CMenuXP - The Office XP Style Menu

By Jean-Michel LE FOL | 13 Jul 2003
Owner drawn menu with the Office XP visual style
2 votes, 1.8%
1
2 votes, 1.8%
2
2 votes, 1.8%
3
8 votes, 7.1%
4
98 votes, 87.5%
5
4.93/5 - 143 votes
6 removed
μ 4.74, σa 1.29 [?]

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)

    About the Author

    Jean-Michel LE FOL

    Web Developer
    CSC
    France France

    Member
    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.

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    GeneralMy vote of 4 Pinmemberunlimited298918:48 19 Apr '11  
    QuestionHow did it redraw the background of the menu bar? Pinmemberlihnux16:42 10 Jun '10  
    GeneralMenubar background bug Pinmembersapero_12:23 13 Dec '09  
    QuestionWould not see why VS2008 is the menu? Pinmemberlee eun sung18:49 2 Dec '09  
    Generalimages for submenus (i know how) PinmemberToxa-TLT3:41 22 Sep '09  
    GeneralLisence for this code Pinmemberramanujamkv20:06 29 Jun '09  
    GeneralRe: License for this code PinmemberJean-Michel LE FOL23:25 29 Jun '09  
    GeneralRe: License for this code Pinmemberramanujamkv1:14 30 Jun '09  
    GeneralI'm new player,english is very poor,my skype ID is "liu_zheng82" we are make friend Pinmembermimijiang22:59 31 May '09  
    GeneralThe system nenu was mess up Pinmemberjohnxwang10:34 15 Oct '08  
    GeneralRe: The system nenu was mess up Pinmemberjohnxwang10:45 15 Oct '08  
    QuestionExcellent project. Did anyone try to implement this in a non-mfc app (.c file) PinmemberSukar9:32 16 Jun '08  
    GeneralBig icons PinmemberNguyen Hoang Quynh0:02 3 Mar '08  
    Questionsystem menu is bad in SDI? PinmemberAjean16:58 9 Apr '07  
    Generalhelp i can not make menu item greyed. PinmemberRichard Chan7:06 26 Nov '06  
    plz help me check this! i used this menu class in dialog
    GeneralRe: help i can not make menu item greyed. PinmemberOgottogottogott22:23 13 Dec '06  
    GeneralIt doesn't work with dialog based programme Pinmembersting_lee22:56 5 Jul '06  
    QuestionChanging Menu Font at run-time ??? Pinmemberana_v12322:22 5 Apr '06  
    QuestionCMenuXP on certain menus Pinmembermyst4ever14:28 26 Feb '06  
    AnswerRe: CMenuXP on certain menus PinmemberParampreet Sidhu6:02 2 Mar '07  
    GeneralBug: It doesn't work with right to left style Pinmemberk_dehairy23:42 15 Feb '06  
    QuestionAnyone can help to solve this? PinmemberEinst14:01 7 Jan '06  
    AnswerRe: Anyone can help to solve this? Pinmemberbarnabe4221:42 30 Jan '07  
    GeneralThank You PinmemberEinst1:24 7 Jan '06  
    GeneralNovice-I need help to implement this class!! Pinmemberneobavesten6:58 28 Nov '05  

    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.

    Permalink | Advertise | Privacy | Mobile
    Web02 | 2.5.120210.1 | Last Updated 14 Jul 2003
    Article Copyright 2002 by Jean-Michel LE FOL
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid