|
OWLNext 7.0
Borland's Object Windows Library for the modern age
|
Enabling and disabling command items is as simple as calling the TCommandEnabler::Enable() function in your handler function.
You decide the criteria for enabling and disabling a particular item. For example, if a particular library is not available, you might want to disable any commands that access that library. If your application handles files in a number of different formats, you might want to disable commands that are not appropriate to the current format.
To enable or disable a command,
The following sample class has a bool flag, IsDirty, to tell if the file has been modified since it was opened or last saved, and a CeFileSave function to enable and disable the File|Save command:
CeFileSave checks the IsDirty flag. If IsDirty is false (the file has not been modified), it disables the CmFileSave command by calling Enable, passing false as the parameter. If IsDirty is true (the file has been modified), CeFileSave enables the CmFileSave command, passing true as the parameter. Because you want to call Enable with the true parameter when IsDirty is true and vice versa, you can just pass IsDirty as the parameter to Enable. This method of enabling and disabling a command works for both menu items and button gadgets. In the preceding example, if you have both a control bar button and a menu item that send the CM_FILESAVE command, both commands are implemented in the CmFileSave function. Similarly, command enabling for the control bar button and the menu item is implemented in the CeFileSave function.