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

CMenuXP - The Office XP Style Menu

, 13 Jul 2003 CPOL
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

     
    BugOnDrawItem error PinmemberRui Frazao10-Sep-12 14:33 
    GeneralRe: OnDrawItem error [modified] PinmemberKoma Wang30-Aug-14 2:03 
    GeneralRe: OnDrawItem error PinmemberKoma Wang31-Aug-14 19:18 
    GeneralMy vote of 4 Pinmemberunlimited298919-Apr-11 18:48 
    Sometime taskbar has error but it is really a good topic
    QuestionHow did it redraw the background of the menu bar? Pinmemberlihnux10-Jun-10 16:42 
    GeneralMenubar background bug Pinmembersapero_13-Dec-09 12:23 
    QuestionWould not see why VS2008 is the menu? Pinmemberlee eun sung2-Dec-09 18:49 
    Generalimages for submenus (i know how) PinmemberToxa-TLT22-Sep-09 3:41 
    GeneralLisence for this code Pinmemberramanujamkv29-Jun-09 20:06 
    GeneralRe: License for this code PinmemberJean-Michel LE FOL29-Jun-09 23:25 

    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
    Web03 | 2.8.1411028.1 | Last Updated 14 Jul 2003
    Article Copyright 2002 by Jean-Michel LE FOL
    Everything else Copyright © CodeProject, 1999-2014
    Layout: fixed | fluid