ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5
part 6


4 - Multiple Menus

One menu can hold quite a few entries, but for access to more entries, or to organize menu options further, we really need more than one menu. For instance, we might want to place editing commands in one menu group, file commands in another, and so on. For this, we can use the CMenuBar object.

If for example we have several menus already set up (m_menu1, m_menu2 and m_menu3), we could create a menu bar to manage them:

m_menuBar=new CMenuBar(ID_MENUBAR,23,this); // create bar
// now add each menu in left to right display order
m_menuBar->AddButton(new CPushButton(ID_MENU1_BUTTON,0,0,"Menu1"),m_menu1);
m_menuBar->AddButton(new CPushButton(ID_MENU2_BUTTON,0,0,"Menu2"),m_menu2);
m_menuBar->AddButton(new CPushButton(ID_MENU3_BUTTON,0,0,"Menu3"),m_menu3);

Again, we create the object and add entries. Note that once we add a button to the menu bar, the CMenu object's memory is managed by the CMenuBar, and shouldn't be deleted directly at the end of the program. However, we now need to delete the CMenuBar object, so our cleanup work isn't over.

This menu bar consists of several buttons, each calling up a menu. To activate it, the MSG_KEY message routine now makes the menu bar visible, rather than any individual menu; that is, m_menuBar->Show() rather than m_menu->Show(). Be careful when formatting the button entries, since although the menus do not appear simultaneously, the buttons do, and because they need to fit all together onscreen, the captions should be short but descriptive.

Once the menu bar is visible along with each button, pressing each calls up the appropriate menu. Also, shortcuts will work once the bar is displayed, rather than only when the specific menu is open, making them more useful in a multiple-menu program.

Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice