Closing all figures associated with a main GUI
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(3 个)
Walter Roberson
2014-1-5
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 个评论
Walter Roberson
2014-1-6
Yes, hObject and eventdata are names commonly generated by GUIDE, but they are the same thing.
Jonathan
2016-9-30
To close all figures while you close the GUI main window, you only need to add "close all" in the CloseRequestFcn.
1 个评论
Walter Roberson
2016-9-30
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!