How do I...?

Ask the User for Confirmation Before Exiting

In AutoPlay Media Studio 5.0, it is possible to stop closing your application based on user input, even after the close button has been pressed, or the Application.Exit action has been used.  This is useful if, for example, you are worried that the user will accidentally close your application, or if you want to allow the user to save their changes before they exit.

To accomplish this, you must include a function (QueryAllowProjectClose) in your Global Functions (Project > Global Functions) that returns true if the program should close, and false if it should not:

function QueryAllowProjectClose()  --this function will be called when the program is exiting
    confirmation = Dialog.Message("Are you sure?", "Are you sure that you want to exit?", MB_YESNO, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
    if confirmation == 6 then      --the yes button was pressed
        return true;     --allow the program to close
    end

    if confirmation == 7 then     --the no button was pressed
        return false;     --tell the program to 'stop closing'
    end

    return true;     --if for any reason confirmation is not set to yes OR no, allow the program to close
end

Note: This function is called internally by your application when it is told to exit.  If true is returned, your application will exit.  If false is returned, your program will not exit.


Applies to:

Standard Edition

Professional Edition