Click here to Skip to main content
Click here to Skip to main content

CMenuXP - The Office XP Style Menu

By , 13 Jul 2003
 

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

     
    Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
    You must Sign In to use this message board.
    Search this forum  
        Spacing  Noise  Layout  Per page   
    BugOnDrawItem errormemberRui Frazao10 Sep '12 - 13:33 
    GeneralMy vote of 4memberunlimited298919 Apr '11 - 17:48 
    QuestionHow did it redraw the background of the menu bar?memberlihnux10 Jun '10 - 15:42 
    GeneralMenubar background bugmembersapero_13 Dec '09 - 11:23 
    QuestionWould not see why VS2008 is the menu?memberlee eun sung2 Dec '09 - 17:49 
    Generalimages for submenus (i know how)memberToxa-TLT22 Sep '09 - 2:41 
    GeneralLisence for this codememberramanujamkv29 Jun '09 - 19:06 
    GeneralRe: License for this codememberJean-Michel LE FOL29 Jun '09 - 22:25 
    GeneralRe: License for this codememberramanujamkv30 Jun '09 - 0:14 
    GeneralI'm new player,english is very poor,my skype ID is "liu_zheng82" we are make friendmembermimijiang31 May '09 - 21:59 
    GeneralThe system nenu was mess upmemberjohnxwang15 Oct '08 - 9:34 
    GeneralRe: The system nenu was mess upmemberjohnxwang15 Oct '08 - 9:45 
    QuestionExcellent project. Did anyone try to implement this in a non-mfc app (.c file)memberSukar16 Jun '08 - 8:32 
    GeneralBig iconsmemberNguyen Hoang Quynh2 Mar '08 - 23:02 
    Questionsystem menu is bad in SDI?memberAjean9 Apr '07 - 15:58 
    Generalhelp i can not make menu item greyed.memberRichard Chan26 Nov '06 - 6:06 
    GeneralRe: help i can not make menu item greyed.memberOgottogottogott13 Dec '06 - 21:23 
    GeneralIt doesn't work with dialog based programmemembersting_lee5 Jul '06 - 21:56 
    QuestionChanging Menu Font at run-time ???memberana_v1235 Apr '06 - 21:22 
    QuestionCMenuXP on certain menusmembermyst4ever26 Feb '06 - 13:28 
    AnswerRe: CMenuXP on certain menusmemberParampreet Sidhu2 Mar '07 - 5:02 
    GeneralBug: It doesn't work with right to left stylememberk_dehairy15 Feb '06 - 22:42 
    QuestionAnyone can help to solve this?memberEinst7 Jan '06 - 13:01 
    AnswerRe: Anyone can help to solve this?memberbarnabe4230 Jan '07 - 20:42 
    GeneralThank YoumemberEinst7 Jan '06 - 0:24 
    GeneralNovice-I need help to implement this class!!memberneobavesten28 Nov '05 - 5:58 
    GeneralNew Usememberphome20 Nov '05 - 14:46 
    QuestionTransparencies?sussjgt0228 Sep '05 - 5:16 
    Answerthe same questionmemberahoye12 Jul '06 - 20:44 
    GeneralFix for SystemMenumemberIngo H. de Boer14 May '05 - 13:08 
    GeneralRe: Fix for SystemMenumemberMORICHIKA6 Sep '05 - 4:12 
    GeneralGreate Fix! Re: Fix for SystemMenumemberxuell001 Dec '05 - 15:50 
    GeneralRe: Fix for SystemMenumemberAdiga7 Nov '06 - 17:51 
    Questionhow to change iconsmembergogo82102829 Apr '05 - 15:54 
    AnswerRe: how to change iconsmemberAdiga7 Nov '06 - 18:18 
    AnswerRe: how to change iconsmemberdragonren_tj27 Dec '07 - 17:02 
    QuestionAre 24-bit images supported in this menu?susskkconcome27 Apr '05 - 13:51 
    QuestionCDateTimeCtrl?memberpoiut6 Apr '05 - 8:18 
    GeneralImages for popup itemsmemberferret-e23 Mar '05 - 7:22 
    GeneralBugs !!memberDJ Mantra13 Feb '05 - 4:49 
    Generalchange the icons....memberManoj Singh K31 Jan '05 - 1:30 
    GeneralRe: change the icons....memberhghn1 Apr '05 - 15:45 
    GeneralRe: change the icons....memberzwergerl16 May '05 - 3:16 
    GeneralRe: change the icons....memberzwergerl15 May '05 - 7:01 
    QuestionGreat ! But help me to fix a bug ?memberNguyen Duc Thien29 Jan '05 - 2:41 
    AnswerRe: Great ! But help me to fix a bug ?memberfjlaga28 Aug '06 - 11:55 
    GeneralMenu Bar FlickermemberGraham G Pearson19 Jan '05 - 0:20 
    QuestionGreat job! Can it support left-side bar?memberlbjerry25 Dec '04 - 3:11 
    GeneralLonghornmemberjung-kreidler21 Dec '04 - 4:34 
    GeneralIf the menu is popup, it does not clear background effect..memberJigar Mehta17 Nov '04 - 21:07 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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