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


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

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:
  2. In the ExitInstance method of your CWinApp derived class:

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.


    • 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
    • 14 Jul 03 - further update by Kris:

      Sample Image


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

    QuestionHow to use in dialog?with icon Pinmembermint13-Apr-02 20:02 
    GeneralGreat Job!!! PinmemberAnonymous12-Apr-02 18:59 
    GeneralExcellent, almost perfect PinmemberSunilTanna27-Mar-02 11:19 
    GeneralRe: Excellent, almost perfect PinmemberJean-Michel LE FOL28-Mar-02 0:08 
    GeneralRe: Excellent, almost perfect PinmemberSunilTanna6-Apr-02 13:49 
    GeneralRe: Excellent, almost perfect PinmemberJean-Michel LE FOL7-Apr-02 0:21 
    GeneralRe: Excellent, almost perfect PinmemberSunilTanna7-Apr-02 4:11 
    Generallittle improvements with Multiple documents Pinmemberpepito sbarzeguti22-Mar-02 2:10 
    a little impovement for MDI with multiple documents:
    Change CMenuXP class in:
    class CMenuXP : public CMenu
    // Attributes
          static CMap <int, int, CString, CString&>   m_sCaptions;
          static CMap <int, int, CImgDesc, CImgDesc&> m_Images;
    // Operations
          static void SetWinXPStyle (HMENU hMenu, CWnd* pWnd = NULL);
          static bool IsOwnerDrawn (HMENU hMenu);
          static void OnMeasureItem (MEASUREITEMSTRUCT* pMeasureItemStruct);
          static void OnDrawItem (DRAWITEMSTRUCT* pDrawItemStruct);
          static LRESULT OnMenuChar (HMENU hMenu, UINT nChar, UINT nFlags);
    // new code !
          static CImageList                                       m_ImageList;
          static int   AddImage(HIMAGELIST hSourceImgList,int sourceImageIndex);
    // end new code...
    add in menuxp.cpp
    CMap <int, int, CString, CString&>      CMenuXP::m_sCaptions;
    CMap <int, int, CImgDesc, CImgDesc&>   CMenuXP::m_Images;
    CImageList                                          CMenuXP::m_ImageList; // new initialization
    int   CMenuXP::AddImage(HIMAGELIST hSourceImgList,int sourceImageIndex)
             int   index=-1;
             if( hSourceImgList && sourceImageIndex > -1 ){
                HICON hIcon = ::ImageList_ExtractIcon(
                                                          NULL                     ,
                                                          hSourceImgList      ,
                                                          sourceImageIndex   );
                if( hIcon ){
                      if( CMenuXP::m_ImageList.m_hImageList == NULL )
                         CMenuXP::m_ImageList.Create(16            ,   // cx,
                                                                   16            ,   // cy,
                                                                   ILC_MASK   ,   // nFlags,
                                                                   0               ,   // int nInitial,
                                                                   16            ); // grow...
                      if( CMenuXP::m_ImageList.m_hImageList != NULL ){
             return index;

    and in the function SetWinXPStyle sostitute:
                                                    //----------- Previus code:
                                                    // CImgDesc imgDesc (
                                                    // (HIMAGELIST)pBar->SendMessage (TB_GETIMAGELIST, 0,   0), tbbi.iImage);
                                                    // m_Images.SetAt (mii.wID, imgDesc);
                                                    // ---------- New code...
                                                    if( (nMyImageIndex=AddImage(
                                                             (HIMAGELIST)pBar->SendMessage(TB_GETIMAGELIST, 0, 0),
                                                                      tbbi.iImage)) > -1 ){
                                                          CImgDesc imgDesc(CMenuXP::m_ImageList.m_hImageList,nMyImageIndex);
                                                          m_Images.SetAt( mii.wID, imgDesc );
    In this way if you destroy some toolbars etc.. at runtime the image is correct..
    Sorry for my poor english and thanks for your job
    GeneralRequest: Blue border PinmemberGertschi10-Mar-02 1:49 
    GeneralOk in the WTL version PinmemberJean-Michel LE FOL19-Mar-02 22:12 
    GeneralLarge Toolbar Icon PinmemberSim Bo Jun4-Mar-02 2:43 
    GeneralRe: Large Toolbar Icon Pinmemberigor19601-May-02 19:52 
    GeneralRe: Large Toolbar Icon PinmemberEduard Huguet29-May-02 1:05 
    QuestionCan we draw on menubar also ? PinmemberAbhishek Narula26-Feb-02 3:22 
    AnswerRe: Can we draw on menubar also ? PinmemberPaul A. Howes26-Feb-02 3:36 
    AnswerOk in the WTL version PinmemberJean-Michel LE FOL19-Mar-02 22:13 
    GeneralArticle updated ! PinmemberJean-Michel LE FOL24-Feb-02 6:39 
    GeneralRe: Article updated ! Pinmemberxxxyyyzzz25-Feb-02 6:06 
    GeneralI'm preparing a new (better?) version PinmemberJean-Michel LE FOL18-Feb-02 3:04 
    GeneralRe: I'm preparing a new (better?) version PinmemberCosmoS2k22-Feb-02 21:33 
    GeneralNice job, however it's uneasy to reuse! Pinmemberxxxyyyzzz17-Feb-02 11:18 
    GeneralNeeds some work PinmemberJase Jennings16-Feb-02 13:16 
    GeneralVisual Studio .NET one bug PinmemberCosmoS2k16-Feb-02 12:02 
    GeneralBug : All menu Item as Submenu PinmemberSephiroth11-Feb-02 23:49 
    GeneralRe: Bug : All menu Item as Submenu PinmemberSephiroth12-Feb-02 0:54 

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