5,557,174 members and growing! (16,650 online)
Email Password   helpLost your password?
Desktop Development » Menus » Custom menus     Intermediate

CMenuXP - The Office XP Style Menu

By Jean-Michel LE FOL

Owner drawn menu with the Office XP visual style
VC6, VC7, C++Windows, NT4, Win2K, WinXP, MFC, VS.NET2002, VS6, Visual Studio, Dev

Posted: 7 Feb 2002
Updated: 13 Jul 2003
Views: 410,866
Bookmarked: 161 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
134 votes for this Article.
Popularity: 10.06 Rating: 4.73 out of 5
2 votes, 1.9%
1
2 votes, 1.9%
2
2 votes, 1.9%
3
7 votes, 6.8%
4
90 votes, 87.4%
5

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Jean-Michel LE FOL


    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.
    Occupation: Web Developer
    Company: CSC
    Location: France France

    Other popular Menus articles:

    Article Top
    Sign Up to vote for this article
    You must Sign In to use this message board.
    FAQ FAQ Noise ToleranceSearch Search Messages 
     Layout  Per page   
     Msgs 1 to 25 of 329 (Total in Forum: 329) (Refresh)FirstPrevNext
    Subject  Author Date 
    GeneralThe system nenu was mess upmemberjohnxwang1 hr 38mins ago 
    GeneralRe: The system nenu was mess upmemberjohnxwang1 hr 27mins ago 
    QuestionExcellent project. Did anyone try to implement this in a non-mfc app (.c file)memberSukar9:32 16 Jun '08  
    GeneralBig iconsmemberNguyen Hoang Quynh0:02 3 Mar '08  
    Questionsystem menu is bad in SDI?memberAjean16:58 9 Apr '07  
    Generalhelp i can not make menu item greyed.memberRichard Chan7:06 26 Nov '06  
    GeneralRe: help i can not make menu item greyed.memberOgottogottogott22:23 13 Dec '06  
    GeneralIt doesn't work with dialog based programmemembersting_lee22:56 5 Jul '06  
    GeneralChanging Menu Font at run-time ???memberana_v12322:22 5 Apr '06  
    QuestionCMenuXP on certain menusmembermyst4ever14:28 26 Feb '06  
    AnswerRe: CMenuXP on certain menusmemberParampreet Sidhu6:02 2 Mar '07  
    GeneralBug: It doesn't work with right to left stylememberk_dehairy23:42 15 Feb '06  
    GeneralAnyone can help to solve this?memberEinst14:01 7 Jan '06  
    GeneralRe: Anyone can help to solve this?memberbarnabe4221:42 30 Jan '07  
    GeneralThank YoumemberEinst1:24 7 Jan '06  
    GeneralNovice-I need help to implement this class!!memberneobavesten6:58 28 Nov '05  
    GeneralNew Usememberphome15:46 20 Nov '05  
    GeneralTransparencies?sussjgt026:16 28 Sep '05  
    Generalthe same questionmemberahoye21:44 12 Jul '06  
    GeneralFix for SystemMenumemberIngo H. de Boer14:08 14 May '05  
    GeneralRe: Fix for SystemMenumemberMORICHIKA5:12 6 Sep '05  
    GeneralGreate Fix! Re: Fix for SystemMenumemberxuell0016:50 1 Dec '05  
    GeneralRe: Fix for SystemMenumemberAdiga18:51 7 Nov '06  
    Generalhow to change iconsmembergogo82102816:54 29 Apr '05  
    GeneralRe: how to change iconsmemberAdiga19:18 7 Nov '06  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 13 Jul 2003
    Editor: Chris Maunder
    Copyright 2002 by Jean-Michel LE FOL
    Everything else Copyright © CodeProject, 1999-2008
    Web17 | Advertise on the Code Project