Click here to Skip to main content
11,478,902 members (65,164 online)
Click here to Skip to main content

CMenuXP - The Office XP Style Menu

, 13 Jul 2003 CPOL 742.9K 26.1K 238
Rate this:
Please Sign up or sign in to vote.
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)

    Share

    About the Author

    Jean-Michel LE FOL
    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

     
    AnswerRe: Anyone can help to solve this? Pin
    barnabe4230-Jan-07 21:42
    memberbarnabe4230-Jan-07 21:42 
    GeneralThank You Pin
    Einst7-Jan-06 1:24
    memberEinst7-Jan-06 1:24 
    GeneralNovice-I need help to implement this class!! Pin
    neobavesten28-Nov-05 6:58
    memberneobavesten28-Nov-05 6:58 
    GeneralNew Use Pin
    phome20-Nov-05 15:46
    memberphome20-Nov-05 15:46 
    QuestionTransparencies? Pin
    jgt0228-Sep-05 6:16
    sussjgt0228-Sep-05 6:16 
    Answerthe same question Pin
    ahoye12-Jul-06 21:44
    memberahoye12-Jul-06 21:44 
    GeneralFix for SystemMenu Pin
    Ingo H. de Boer14-May-05 14:08
    memberIngo H. de Boer14-May-05 14:08 
    GeneralRe: Fix for SystemMenu Pin
    MORICHIKA6-Sep-05 5:12
    memberMORICHIKA6-Sep-05 5:12 
    GeneralGreate Fix! Re: Fix for SystemMenu Pin
    xuell001-Dec-05 16:50
    memberxuell001-Dec-05 16:50 
    GeneralRe: Fix for SystemMenu Pin
    Adiga7-Nov-06 18:51
    memberAdiga7-Nov-06 18:51 
    Questionhow to change icons Pin
    gogo82102829-Apr-05 16:54
    membergogo82102829-Apr-05 16:54 
    AnswerRe: how to change icons Pin
    Adiga7-Nov-06 19:18
    memberAdiga7-Nov-06 19:18 
    AnswerRe: how to change icons Pin
    dragonren_tj27-Dec-07 18:02
    memberdragonren_tj27-Dec-07 18:02 
    QuestionAre 24-bit images supported in this menu? Pin
    kkconcome27-Apr-05 14:51
    susskkconcome27-Apr-05 14:51 
    QuestionCDateTimeCtrl? Pin
    poiut6-Apr-05 9:18
    memberpoiut6-Apr-05 9:18 
    GeneralImages for popup items Pin
    ferret-e23-Mar-05 8:22
    memberferret-e23-Mar-05 8:22 
    GeneralBugs !! Pin
    DJ Mantra13-Feb-05 5:49
    memberDJ Mantra13-Feb-05 5:49 
    Generalchange the icons.... Pin
    Manoj Singh K31-Jan-05 2:30
    memberManoj Singh K31-Jan-05 2:30 
    GeneralRe: change the icons.... Pin
    hghn1-Apr-05 16:45
    memberhghn1-Apr-05 16:45 
    GeneralRe: change the icons.... Pin
    zwergerl16-May-05 4:16
    memberzwergerl16-May-05 4:16 
    GeneralRe: change the icons.... Pin
    zwergerl15-May-05 8:01
    memberzwergerl15-May-05 8:01 
    QuestionGreat ! But help me to fix a bug ? Pin
    Nguyen Duc Thien29-Jan-05 3:41
    memberNguyen Duc Thien29-Jan-05 3:41 
    AnswerRe: Great ! But help me to fix a bug ? Pin
    fjlaga28-Aug-06 12:55
    memberfjlaga28-Aug-06 12:55 
    GeneralMenu Bar Flicker Pin
    Graham G Pearson19-Jan-05 1:20
    memberGraham G Pearson19-Jan-05 1:20 
    QuestionGreat job! Can it support left-side bar? Pin
    lbjerry25-Dec-04 4:11
    memberlbjerry25-Dec-04 4:11 
    GeneralLonghorn Pin
    jung-kreidler21-Dec-04 5:34
    memberjung-kreidler21-Dec-04 5:34 
    GeneralIf the menu is popup, it does not clear background effect.. Pin
    Jigar Mehta17-Nov-04 22:07
    memberJigar Mehta17-Nov-04 22:07 
    GeneralProblem: disabled / grayed menu items appear enabled Pin
    Ronen Babayoff16-Oct-04 3:38
    memberRonen Babayoff16-Oct-04 3:38 
    GeneralRe: Problem: disabled / grayed menu items appear enabled Pin
    vlarin18-Mar-05 0:28
    membervlarin18-Mar-05 0:28 
    GeneralRe: Problem: disabled / grayed menu items appear enabled Pin
    alex_ger24-May-05 14:42
    memberalex_ger24-May-05 14:42 
    GeneralCMenuXP::OnMeasureItem Question Pin
    Frank Lagattuta30-Sep-04 23:23
    memberFrank Lagattuta30-Sep-04 23:23 
    Generalcontext menu on windows shelf Pin
    mickelliot3-Sep-04 16:42
    membermickelliot3-Sep-04 16:42 
    Questionhow to get default system menu Pin
    wangxin011817-Jul-04 7:32
    susswangxin011817-Jul-04 7:32 
    QuestionCan't we apply image to menu with updated XP menu files??? Pin
    Jigar Mehta24-Jun-04 3:49
    memberJigar Mehta24-Jun-04 3:49 
    AnswerRe: Can't we apply image to menu with updated XP menu files??? Pin
    Jigar Mehta17-Nov-04 22:33
    memberJigar Mehta17-Nov-04 22:33 
    AnswerRe: Can't we apply image to menu with updated XP menu files??? Pin
    Jigar Mehta17-Nov-04 22:33
    memberJigar Mehta17-Nov-04 22:33 
    GeneralColouring the MENU BAR Pin
    Alex Evans20-Jun-04 23:15
    memberAlex Evans20-Jun-04 23:15 
    GeneralColouring the MENU BAR Pin
    Alex Evans20-Jun-04 23:04
    memberAlex Evans20-Jun-04 23:04 
    GeneralAuthorize Pin
    kenhru12-Jun-04 5:53
    memberkenhru12-Jun-04 5:53 
    GeneralLicensing?! Pin
    ge99819211-Jun-04 17:27
    memberge99819211-Jun-04 17:27 
    GeneralThank you for your compliments! Pin
    Jean-Michel LE FOL11-Jun-04 19:51
    memberJean-Michel LE FOL11-Jun-04 19:51 
    GeneralRe: Thank you for your compliments! Pin
    Lee Bamford17-Dec-04 4:38
    memberLee Bamford17-Dec-04 4:38 
    GeneralMenuXP with MFC in a shared vs static Library Pin
    Vivian De Smedt1-Jun-04 3:18
    memberVivian De Smedt1-Jun-04 3:18 
    QuestionWhat is the problem? Pin
    MangoBoy27-May-04 23:15
    memberMangoBoy27-May-04 23:15 
    GeneralBug Report Pin
    miracle_chen20-May-04 4:20
    membermiracle_chen20-May-04 4:20 
    GeneralRe: Bug Report Pin
    http97428-May-05 8:52
    memberhttp97428-May-05 8:52 
    GeneralRe: Bug Report Pin
    http97428-May-05 21:40
    memberhttp97428-May-05 21:40 
    GeneralRe: Bug Report Pin
    Rui Frazao10-Sep-12 13:59
    memberRui Frazao10-Sep-12 13:59 
    GeneralBug report Pin
    retinex26-Apr-04 20:43
    memberretinex26-Apr-04 20:43 
    GeneralRe: Bug report Pin
    badger23025-May-04 11:42
    memberbadger23025-May-04 11:42 

    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.

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