Creating Graphical User Interfaces    

Generate Callback Function Prototypes

When you select Generate callback function prototypes in the GUI Options dialog, GUIDE adds a subfunction to the GUI M-file for any component you add to the GUI (note that frame, axes, and static text components do not use their Callback property and therefore have no subfunction). You must then write the code for the callback in this subfunction.

GUIDE also adds a subfunction whenever you edit a callback routine from the Layout Editor's right-click context menu and when you add menus to the GUI using the Menu Editor.

Naming Callback Subfunctions

When you add a component to your GUI layout, GUIDE assigns a value to its Tag property, which is then used to generate the name of the callback.

For example, the first push button you add to the layout is tagged pushbutton1. When generating the M-file, GUIDE adds a callback subfunction called pushbutton1_Callback. If you define a ButtonDownFcn for the same push button, GUIDE names its subfunction pushbutton1_ButtonDownFcn.

Callback Function Syntax

The callback function syntax is of the form

The arguments are listed in the following table.

hObject
The handle of the object whose callback is executing.
eventdata
Empty -- reserved for future use.
handles
A structure containing the handles of all components in the GUI whose fieldnames are defined by the object's Tag property. Can also be used to pass data to other callback functions or the command line.

For example, if you create a layout having a push button whose Tag property is set to pushbutton1, then GUIDE generates the following subfunction header in the GUI M-file.

Assigning the Callback Property String

When you first add a component to your GUI layout, its Callback property is set to the string %automatic. This string signals GUIDE to replace it with one that calls the appropriate callback subfunction in the GUI M-file when you save or run the GUI. For example, GUIDE sets the Callback property for pushbutton1 uicontrol to

where

See Callback Function Syntax for more information on callback function arguments and Renaming GUI Files and Tags for more information on how to change the names used by GUIDE.


  Generate FIG-File and M-File GUI Allows Only One Instance to Run (Singleton)