Creating Graphical User Interfaces |
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:
MyGui
- is the name of the GUI M-file that launches the figure containing the menus.
menu_edit_selectall_Callback
- is the name of the subfunction callback for the Select All menu item (derived from the Tag
specified in the Menu Editor).
gcbo
- is the handle of the Select All uimenu item.
[]
- is an empty matrix used as a place holder for future use.
guidata(gcbo)
- gets the handles
structure from the figure's application data
Defining Menus for the Menu Bar | Defining Context Menus |