Click here to Skip to main content
Licence 
First Posted 3 Jun 2002
Views 76,402
Bookmarked 21 times

A Simple way to switch from one menu set to another

By | 5 Jun 2002 | Article
Replace your current menus with another set of menus with this function

Basic Purpose

I spent a couple hours today looking for a simple way to change from one set of menus (file, edit, etc.) to another menu set. I came across this code in MSDN, but I didn't see anything like it here on CodeProject, so this is my first article post. I hope someone might find it useful.

How to Use

  1. Create multiple Menu resources in the resource view. The two I will use are IDR_MAINFRAME and IDR_OTHERMENU.
  2. Declare the function in your MainFrame.h (or some other CFrameWnd derived class)
  3. private:
      void ReplaceMenu(UINT n_IDResource);
  4. Add the following to your MainFrame.cpp
  5. void CMainFrame::ReplaceMenu(UINT n_IDResource)
    {
       CMenu NewMenu; // create the new CMenu variable
       NewMenu.LoadMenu(n_IDResource); 
          // Load the menu from the resource passed
       ASSERT(NewMenu);
    
       // Remove and destroy the old menu
       SetMenu(NULL);
       ::DestroyMenu(m_hMenuDefault); 
          // m_hMenuDefault is the menu member variable of CFrameWnd
    
       // Set the menu to the new menu we created
       SetMenu(&NewMenu);
    
       // Set the default menu handler to the handle of our new menu
       m_hMenuDefault = NewMenu.GetSafeHmenu();
    }
  6. Use the function wherever you need just by calling the function passing it the menu resource to use
  7. ReplaceMenu(IDR_OTHERMENU);

Conclusion

You still implement your message map the same way. Although I would suggest prefixing your menu-set's menu functions differently (ex. OnView1TestMe(), OnView2TestMe()) so you can easily tell which functions are for which menu set. Please keep in mind this is my first article, feed back will be read but just take it easy on me I've done a lot of work with split views and replacing views and printing different views and such in split views. I hope to write another article on that stuff in a few months.

-dz [www.dzgraphics.com]

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

dazinith

Web Developer

United States United States

Member

hrm.. been into computers since my tandy 8088.. im 28 years old..

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

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralBetter way Pinmemberericlamiot2:19 29 Aug '06  
GeneralRe: Better way PinmemberYogesh P. Dhakad23:10 8 May '07  
GeneralRe: Better way PinmemberYogesh P. Dhakad23:37 8 May '07  
Generalstore CMenu as a member of CFrameWnd derived class Pinmemberpiide2:30 18 Jul '05  
GeneralAccess violation when called outside of the mainfrm Pinmemberdejavusoft16:12 23 May '05  
GeneralMaximized document Pinmembersimonpp15:24 18 Sep '03  
GeneralHelp me, please Pinmembershantir@ipa.rssi.ru21:12 21 Jul '03  
QuestionHow to get the menu of childframe? Pinmemberhaiyingxu19:24 11 Mar '03  
Generalpossible bug PinmemberWarren Stevens8:34 4 Jun '02  
GeneralRe: possible bug Pinmemberdazinith9:19 4 Jun '02  
GeneralRe: possible bug PinmemberMarc Clifton1:21 7 Jun '02  
Generalcrud.. i think this should have gone in another section Pinmemberdazinith5:06 4 Jun '02  
GeneralRe: crud.. i think this should have gone in another section PinadminChris Maunder21:49 5 Jun '02  

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.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 6 Jun 2002
Article Copyright 2002 by dazinith
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid