Example of the Confirmation Window in Effect

  1. First, download the sample GUI here. Unzip the files and place them wherever you please.

  2. Now, type guide at the command prompt.

    Command prompt

  3. Choose to open the sample GUI by clicking on “Open Existing GUI”. Click on “Browse” to locate where you saved the GUI files.

    GUIDE Screen

  4. Here is what the GUI should look like when you open it:

    GUI Figure

  5. Click on the mfile icon icon on the GUI figure to bring up the accompanying .m file.

  6. Add the following code to the opening function, closeGUI_tutorial_OpeningFcn

    set(handles.figure1,'CloseRequestFcn',@closeGUI);

    Make sure to add the above line of code before this line of code:

    guidata(hObject, handles);
  7. Now, add the following code to the end of the GUI m-file.

    function closeGUI(src,evnt)
    %this function is called when the user attempts to close the GUI window
     
    %this command brings up the close window dialog
    selection = questdlg('Do you want to close the GUI?',...
                         'Close Request Function',...
                         'Yes','No','Yes');
     
    %if user clicks yes, the GUI window is closed, otherwise
    %nothing happens
    switch selection,
       case 'Yes',
        delete(gcf)
       case 'No'
         return
    end
  8. Now, save your .m file and run the GUI. You should see the following GUI appear

    GUI Figure

  9. Now, try to close the GUI. You should see the following appear:

    Close Dialog

  10. Click “yes” to close the GUI, or click “no” to keep it open.

This is the end of the tutorial.

Pages: 1 2