MFC Topics: Maintenance of Menu Items |
|
Menu Enabled or Disabled |
If you have just created a menu and has not yet mapped it to a method that would process its message, the menu is disabled and appears gray. If you map a menu item to a method, it becomes enabled, indicating that the user can use it. In the following window, the New and the Open menu items are disabled while the Exit menu item is enabled:
|
You also can enable or disable a menu item any time you judge this necessary. To visually enable a menu item when designing it, in the Properties window, set its Enabled property to False. To visually enable a menu item, in the Properties window, set its Enabled property to True. To programmatically enable or disable a menu, call the CMenu::EnableMenuItem() method.
If you visually create a menu,, when the application exists, it would delete it and remove its resources from the memory. If you dynamically create a menu, to delete it after using it, you can call the CMenu::DestroyMenu() method. Its syntax is: BOOL DestroyMenu(); As you can see, the method doesn’t take any argument.
Because an application can deal with more than one type of document, using the same menu for different documents is not useful and can be confusing. To address such an issue, you can perform various continuous operations of adding, deleting, enabling, and disabling some menu items. If the documents are significantly different, a better alternative could consist of using different menus in the same application. At one time, you can display one menu. At another time you can, at least temporarily, replace one menu with another. This is made possible by using a combination of the CMenu methods we have reviewed so far.
So far, we have treated the menu in a general concept mostly applied to the main menu. Another type of menu, probably less popular but not uncommon is one that appears when the user clicks an item somewhere in a window. This type of menu is referred to as context-sensitive because it depends on the item that would display it. Just like the main menu, before using a context-sensitive menu, you must first create it and you and you must decide when and where it would be applied. Because an application can be made of various objects, it is up to you to decide what object would use context-sensitive menu and how. Although a context-sensitive menu can display when the user clicks the defined item, to allow the user to perform regular mouse-click actions, a context-sensitive menu is usually made available when the user right-clicks the designated item.
While a main menu usually appears as more than one group of items, a context-sensitive menu usually displays one column. The menu itself is primarily created like any other menu: you first define a popup item and then add the other sub-items. |
|
||
Previous | Copyright © 2006-2007 FunctionX, Inc. | |
|