Programming Guide : Creating a Frame at Runtime : How You Can Build a Frame Dynamically : How You Can Create the Menu
 
Share this page          
How You Can Create the Menu
A frame's menu is a MenuBar object displayed across the top of the window, containing a single line of menu selections. The MenuBar object is contained in the StartMenu attribute of the FrameSource object.
MenuBar objects contain menu groups, which can contain other menu groups, individual menu items, and menu separators. Menu groups allow a variety of menu structures beneath the top level of the menu bar.
To create a menu for your frame, you would perform the following basic steps:
1. Create the MenuBar object, assigning it to the StartMenu attribute of the FrameSource.
2. Create the menu groups that make up the menu bar. For each:
Create the MenuGroup object.
Define its TextLabel attribute. This becomes the initial menu item that appears on the menu bar.
For example, assume that you create two menu groups and assign the value File to the TextValue attribute of one and Edit to the TextValue attribute of the other. After you attach these menu groups to a menu bar, the menu bar presents the selections File and Edit to the user.
Create the menu objects that make up the menu group, set their attributes, and attach them to the menu group.
3. Attach the completed menu group to the menu bar.
To attach a menu object to a menu group or a menu group to the menu bar, set the object's ParentMenuGroup attribute. Setting this attribute attaches the specified MenuGroup, MenuItem, or MenuSeparator to a specified menu.
For example, the DynamicFrame frame uses the reference variable test_menu to hold the individual MenuButton objects as they are created. After they have been created and named, they are attached to the MenuGroup object represented by top_menu:
test_menu.ParentMenuGroup = top_menu;
In effect, the preceding statement says that the menu button represented by test_menu is part of the menu group represented by top_menu. For an example of how to create menu items dynamically, see How You Can Create the Frame Menu Items.