Mathieu - my understanding of the DefaultFigureCloseRequestFcn is that once set at the root level (0), then MATLAB uses this setting for the CloseRequestFcn of all subsequently created figures.
I think what you want to do instead is just modify the CloseRequestFcn for your GUI figure. If you are using GUIDE, then you should click the figure and select (from the menu) View --> View Callbacks --> CloseRequestFcn and the following should appear in the editor
function YourGuiName_CloseRequestFcn(hObject, eventdata, handles)
% Hint: delete(hObject) closes the figure delete(hObject);
You could then change the body to something like
selection = questdlg('Close YourGuiName?',...
'Close Request Function',...
'Yes','No','Yes');
switch selection,
case 'Yes',
delete(hObject);
case 'No'
return
end
To do something more similar to the code you have written in your question, you could do
set(figure_handle,'CloseRequestFcn','my_closereq')
where figure_handle is the handle to your figure. Note how we use CloseRequestFcn (just like the GUIDE approach) which will affect figure_handle only and not be the default behaviour for all other figures.
Try the above and see what happens!
Best Answer