Creating Graphical User Interfaces    

Menu Callbacks

By default, the Callback text field in the Menu Editor is set to the string %automatic. This causes GUIDE to add the empty callback subfunction to the GUI M-file when you save or run the GUI. If you change this string, GUIDE does not add a subfunction for that menu item.

Functions Generated in the GUI M-file

While the Menu Editor generates an empty callback subfunction for every menu and submenu, you may not need to program the callbacks for top-level menus. This is because clicking on a top-level menu automatically displays the submenus.

Consider the example from the previous section, as illustrated in the following picture:

When a user selects the to file item under the Edit menu Copy item, only the to file callback is required to perform the action.

Suppose, however, that only certain objects can be copied to a file. You can use the Copy menu's callback to enable or disable the to file item, depending on the type of object selected.

Syntax of the Callback Subfunction

The GUI M-file contains all callbacks for the GUI, including the menu callbacks. All generated callbacks use the same syntax.

For example, using the Select All menu item from the previous example gives the following callback string:

where:


  Defining Menus for the Menu Bar Defining Context Menus