- Introduction—Types of Menus
- Pull-Down Menus
- Hierarchical Menus
- Pop-Up Menus
- Menu Objects, Menu IDs and Item Numbers, Command IDs, and Menu Lists
- Creating Your Application's Menus
- Providing Help Balloons (Mac OS 8/9)
- Changing Menu Item Appearance
- Adding Items to a Menu
- Associating Data with Menu Items
- Handling Menu Choices
- Hiding and Showing the Menu Bar
- Accessing Menus from Alerts and Dialogs
- Main Menu Manager Constants, Data Types, and Functions
- Demonstration Program Menus1 Listing
- Demonstration Program Menus1 Comments
- Demonstration Program Menus2 Listing
- Demonstration Program Menus2 Comments
Changing Menu Item Appearance
Menu Manager functions may be used to change the appearance of items in a menu, for example, the font style, text or other characteristics.
Enabling and Disabling Menu Items
Specific menu items or entire menus may be disabled and enabled using DisableMenuItem and EnableMenuItem, which both take a reference to the menu object that identifies the desired menu and either the item number of the menu to be enabled/disabled or a value of 0 to indicate that the entire menu is to be enabled/disabled. Alternatively, if your application uses command IDs to identify menu items, you should use the functions EnableMenuCommand and DisableMenuCommand to enable and disable items.
When an entire menu is disabled or enabled, DrawMenuBar should be called to update the appearance of the menu bar. If you do not need to update the menu bar immediately, you can use InvalMenuBar instead of DrawMenuBar, causing the Event Manager to redraw the menu bar the next time it scans for update events. This will reduce the menu bar flicker that will occur if DrawMenuBar is called more than once in rapid succession.
If you disable an entire menu, the Menu Manager dims that menu's title at the next call to DrawMenuBar and dims all menu items when it displays the menu. If you enable an entire menu, the Menu Manager enables only the menu title and any items that you did not previously disable individually.
Enabling the Preferences... Item in the Application Menu
The Preferences... item in the Mac OS X Application menu is disabled by default. If your application needs to allow the user to invoke a Preferences dialog by choosing this item, it must explicitly enable the item. The following shows how to enable the Preferences... item:
EnableMenuCommand(NULL,kHICommandPreferences);
Other Appearance Changes
The following lists other functions related to changing the appearance of menu items.
Function |
Description |
SetMenuItemText SetMenuItemTextWithCFString GetMenuItemText |
Set and get the text. |
SetItemStyle GetItemStyle |
Set and get the font style. |
SetItemMark GetItemMark |
Set and get the marking character. |
SetItemIcon GetItemIcon |
Set and get the icon ('ICON' or 'cicn') using a resource ID. |
CheckMenuItem |
Places and removes a checkmark at the left of the item text. |
SetMenuItemFontID GetMenuItemFontID |
Set and get the font. SetMenuItemFontID allows you to set up a font menu with each item being drawn in the actual font. |
SetMenuItemIconHandle GetMenuItemIconHandle |
Set and get the icon (icon suite, 'ICON' or 'cicn') using an icon handle. Provides, in conjuction with the 'xmnu' resource, the support for icon suites introduced with Mac OS 8. |
SetMenuItemKeyGlyph GetMenuItemKeyGlyph |
SetMenuItemKeyGlyph substitutes a keyboard glyph for that normally displayed for a menu item's keyboard equivalent. GetMenuItemKeyGlyph gets the keyboard glyph for the keyboard equivalent. |
SetMenuFont GetMenuFont |
Set and get the font used in an individual menu. |
SetMenuExcludesMarkColumn GetMenuExcludesMarkColumn |
Set and get whether an individual menu contains space for marking characters. |