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


2 - Minimalist Menus

At the very least, then, a basic menu would be set up as the program starts (such as in the main window's constructor), and might look like this:
m_menu=new CMenu(ID_MENU,0,32767,0,this);
m_menu->SetNumRows(3);
int row=-1;
m_menu->SetRow(++row,IDM_HELP,"Help",'h');
m_menu->SetSeparatorRow(++row);
m_menu->SetRow(++row,IDM_EXIT,"Exit",'x');

Menu creation consists of creating a CMenu object, setting the number of display rows, and then filling them using the SetRow() function for text, and SetSeparatorRow() to add a horizontal dividing bar. Row items are indexed, and using these index values, SetRow() can be called later in the program to change row entries, such as for toggling menu options. For easier code maintenance, I use a row counter rather than a constant value for the row indexes in this example - when I want to insert a new row, it avoids having to renumber all the index entries.

Unlike other objects typically used in an ebm program, CMenu does not need a parent. Because we don't use SetChild(), memory deletion remains our responsibility. From the code example, this may not seem to be the case, since we pass it the 'this' pointer, but this parameter actually indicates only where menu messages are sent, not object ownership. If we instead use 0 (NULL) here, menu messages are passed to the top message handler, found in GUI_main(). However, good C++ programming emphasizes object encapsulation, using the class to wrap up as many details as possible. For that reason, it's best to use 'this', and handle menu messages in the window's message handler rather than GUI_main().

Some of the other CMenu options may appear unusual - "0,32767,0" refers to the x and y position, and the bar height. Although you can adjust them (for instance, setting y to zero will place the menu at the top rather than the bottom of the screen), it's best to leave them alone, as this makes the menu nonstandard. Not only is an unusual menu interface harder on users, it's an official GUI display no-no from Franklin, and would need to be changed if you wished to offer your program for sale on their website.

Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice