Quit Application Event
To handle the Quit Application event, your application should take any
actions that are necessary before it is terminated (such as saving any open
documents). The following program shows an example of a handler for the Quit Application event.
event immediately after a Print Documents event. The Finder also sends your
application a Quit Application event if the user chooses Restart or Shut Down from the Finder's Special menu. // A handler for the Quit Application event
// Assuming inclusion of
#include <AppleEvents.h>
long handlerRefcon);
Boolean MyPrepareToTerminate (void); long handlerRefcon)
{
// check for missing required parameters
myErr = MyGotRequiredParams( theAppleEvent);
if ( myErr) {
// an error occurred: do the necessary error handling
return myErr;
}
userCanceled = MyPrepareToTerminate();
if (userCanceled)
else
}
The handler in this program calls another function supplied by the
application, the MyPrepareToTerminate function. This function saves the
documents for any open windows and returns a Boolean value that indicates whether the Quit request was canceled by the user. This is another example of isolating code for interacting with the user from the code that performs the
requested action. Structuring your application in this way allows your
application to use the same routine when responding to a user event (such as
choosing the Quit command from the File menu) or to the cor responding Apple event.
Note that your handler must not call the ExitToShell procedure. In the program above, the application calls the ExitToShell procedure only if the handler returns noErr as its function result.
A listing of MyGotRequiredParams may be found under