Creating Graphical User Interfaces Previous page   Next Page

Generate Callback Function Prototypes

When you select Generate callback function prototypes in the GUI Options dialog, GUIDE adds the most commonly used subfunctions to the GUI M-file for any component you add to the GUI. 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.

Argument
Description
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 a 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 Changing Tag and Callback Properties for more information on how to change the names used by GUIDE.

Adding Callbacks to the M-file

If you want GUIDE to include other callbacks in the GUI M-file and provide names for them, you can do one of the following:


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

© 1994-2005 The MathWorks, Inc.