Closing all figures associated with a main GUI
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am programming a GUI that consists of a main window and several other figures. I want that all figures associated with this GUI will close when I close the main window.
So far I tried to use the CloseRequestFcn to do so but I have problems to assign the handles structure that contains the handles to the other figures to the CloseRequestFcn:
if true
set(h.mainControlsFigure,'CloseRequestFcn',@Interferometer_8_main_close_Fcn, h)
end
creates an error in matlab.
On the other hand the matlab documentation gives an example for the use of the CloseRequestFcn where two arguments (src and evnt) are assigned whichs meaning is not clear to me:
if true
Interferometer_8_main_close_Fcn(src,evnt)
end
Furthermore, in which case should I use the CloseRequestFcn and in which case the deleteFcn?
I would be very grateful if somebody could bring some light into the darkness of the CloseRequestFcn and maybe suggest a suitable solution.
Thanks, Christine
0 comentarios
Respuestas (3)
Walter Roberson
el 5 de En. de 2014
set(h.mainControlsFigure,'CloseRequestFcn',@(src,evnt) Interferometer_8_main_close_Fcn(src, evnt, guidata(h.mainControlsFigure))
For almost all callbacks, MATLAB automatically supplies two arguments, the first of which is the object that the callback relates to, and the second of which is a structure that has some details about the callback (for example which key was pressed for a key-press callback).
The form of the code I used above is needed so that the extra handles structure that gets passed to your callback is an up-to-date version at execution time of the callback instead of it being set at the time the callback is created.
2 comentarios
Walter Roberson
el 6 de En. de 2014
Yes, hObject and eventdata are names commonly generated by GUIDE, but they are the same thing.
Jonathan
el 30 de Sept. de 2016
To close all figures while you close the GUI main window, you only need to add "close all" in the CloseRequestFcn.
1 comentario
Walter Roberson
el 30 de Sept. de 2016
Caution:
- "close all" does not close hidden figures. You need "close all hidden" to close hidden figures.
- "close all" is going to close all non-hidden figures, which would also affect figures not associated with the main GUI. If you are creating a system with multiple figures then you may need to be more selective about what you close.
Ver también
Categorías
Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!