### Menus

A menu is a window that contains a list of items--text strings, bitmaps, or images drawn by an application--that enables the user to choose from these predetermined choices using a mouse or keyboard. The types of menus are the menu bar, pull-down menu, cascaded menu, pop-up menu, and system menu. A menu can be created dynamically using program functions, or it can loaded from a resource file. A menu is always owned by another window, usually a frame window.

A menu item is a representation of one of these predetermined choices. A menu item can represent either a command choice, or it can represent an item that when selected, brings up an additional list of choices to choose from. When a user selects a menu item which represents a command choice, a menu selection event is sent to a command handler.

#### Menu Bars and Pull-Down menus

The menu bar is the area near the top of a window, below the title bar and above the client area of the window. A menu bar is a horizontal menu that contains a list of choices. When a user selects a choice on a menu bar, a pull-down menu associated with that choice is displayed. A pull-down menu is a vertical menu that appears below the menu bar as the result of selecting a menu item that represents this list of choices. Typically, all of the menu items on a menu bar represent pull-down menus. In turn, a pull-down menu item can display another pull-down menu item, also called a cascaded menu. It is recommended by several GUI style guides that you use no more than three levels of cascaded menus or create a dialog when you have more than three. The pull-down menus ordinarily are hidden, but they become visible when the user makes a selection from the menu bar.

The User Interface Class Library provides the IMenu and IMenuBar classes to allow you to create menu bars, menu items, and pull-down menus or map those items from a menu loaded from a resource. The IMenu class is an abstract base class that provides the common behavior shared by all of the IMenu derived classes, including IMenuBar, IPopUpMenu, ISubMenu, and ISystemMenu. It contains member functions that can be used to manipulate menus according to the needs of your application. You can add, replace, remove, select, and disable menu items in the menu. This class also provides functions to access properties such as the following:

- The color of the menu
- The number of menu items in the menu
- The bounding rectangle for menu items in the menu

Objects of the IMenu (and derived) classes are not windows themselves. This is due to the implementation of menus in the Windows operating system as non-client areas of the frame. Application code, which relies on the fact that an IMenu is a window in the OS/2 operating system, may not be portable to the Windows operating system.

To support menus loaded from a resource file, IMenu classes have the following requirements:

- Menu resources must be defined using the PM MENU keyword or Windows MENUEX keyword.
- Unique IDs must be provided for all pop-up menu items, indicated by the POPUP keyword.

IMenu does not support conditional cascading behavior or the drawItem style (drawn buttons) in menus.

The User Interface Class Library provides a callback routine to process the following menu events:

- Showing a menu on the display
- Selecting a menu item in a menu
- Removing a menu from the display

#### Pop-Up Menus

A pop-up menu is a menu that is displayed when a user presses the appropriate key or mouse button. A pop-up menu contains choices that can be applied to an object at the time the menu is displayed.

The User Interface Class Library provides the IPopUpMenu and IMenuHandler classes to manipulate pop-up menus. To display a pop-up menu in your application, derive your class from IMenuHandler, override the makePopUpMenu function, and construct an IPopUpMenu object.

Windows

Adding Menus to your Application
Adding a Menu Bar

IMenu
IMenuBar
IPopUpMenu
ISubMenu
ISystemMenu
IWindow