Specifications

4 Programming GUIs
4-24
Making a GUI Figure Modal
Set the GUI figure’s WindowStyle property to modal to make the window
modal. You can use the Property Inspector to change this property or add a
statement in the initialization section of the application M-file, using the
handle returned by
openfig with the set command.
set(fig,'WindowStyle','modal')
Dismissing a Modal Figure
A GUI using a modal figure must take one of the following actions in a callback
routine to release control:
Delete the figure.
delete(figure_handle)
Make the figure invisible.
set(figure_handle,'Visible','off')
Change the figure’s WindowStyle property to normal.
set(figure_handle,'WindowStyle','normal')
The user can also type Control+C in a modal figure to convert it to a normal
window.
Obtaining the Figure Handle from Within a Callback. In general, dismissing a modal
figure requires the handle of the figure. Since most GUIs hide figure handles
to prevent accidental access, the
gcbf (get callback figure) command provides
the most effective method to get the figure handle from within a callback
routine.
gcbf returns the handle of the figure containing the object whose callback is
executing. This enables you to use
gcbf in the callback of the component that
will dismiss the dialog. For example, suppose your dialog includes a push
button (tagged
pushbutton1) that closes the dialog. Its callback could include
a call to
delete at the end of its callback subfunction.
function varargout = pushbutton1_Callback(h,eventdata,handles,varargin)
% Execute code according to dialog design
.
.
.
% Delete figure after user responds to dialog
delete(gcbf)