Specifications

4 Programming GUIs
4-8
Positioning the GUI Onscreen
The application M-file uses the movegui command to ensure the GUI figure is
visible on the screen of the target computer, regardless of the screen size and
resolution. If the specified figure position would result in the GUI being placed
off screen,
movegui moves the figure to the nearest on-screen location with
respect to the specified position.
The statement in the application M-file is
movegui(fig,'onscreen')
where fig is the handle of GUI figure returned by the openfig command.
movegui also provides options to place the GUI at specific locations on the
screen.
Creating and Storing the Handles Structure
When you launch the GUI, the application M-file creates a structure that saves
the handles of all the components in the GUI. GUIDE stores this structure in
the figure’s application data so that it can be retrieved when needed (e.g., from
a callback subfunction).
The name of the structure field containing a given object’s handle is taken from
the object’s
Tag property. For example, an object with a Tag value of
pushbutton1 is accessed with
handles.pushbutton1
You can access the figure’s hidden handle in a similar way. If the figure’s Tag
is
figure1, then
handles.figure1
contains the figure’s handle.
The application M-files uses
guihandles and guidata to create and store the
structure.
handles = guihandles(fig); % Create handle struct
guidata(fig,handles); % Save struct in figure’s app data
Note that only those components whose Tag property is set to a string that is a
valid variable name are included in this structure. Use
isvarname to determine
if a string is a valid name.