Creating Graphical User Interfaces |
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
.
The callback function syntax is of the form
The arguments are listed in the following table.
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
my_gui
is the name of the GUI M-file.
pushbutton1
is the value of the component's Tag
property.
pushbutton1_Callback
is the name of the callback routine subfunction defined in my_gui
.
gcbo
is a command that returns the handle of the callback object (i.e., pushbutton1
).
[]
is a place holder for the currently unused eventdata
argument.
guidata
(gcbo)
returns the handles
structure.
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:
KeyPressFcn
, to the string %automatic
. GUIDE adds the callback to the M-file the next time you save the GUI.
Generate FIG-File and M-File | GUI Allows Only One Instance to Run (Singleton) |
© 1994-2005 The MathWorks, Inc.