Quitting an Application
Eventually the user will quit your application, usually by choosing Quit from the File menu (or by pressing the usual keyboard equivalent, Command-Q). At that time, you should close all windows, release any memory you still are holding, and exit your main event loop. Listing 9-4 shows theDoQuitroutine called by the Venn Diagrammer application when the user chooses Quit from the File menu.Listing 9-4 Quitting your application
PROCEDURE DoQuit; VAR myWindow: WindowPtr; BEGIN myWindow := FrontWindow; {close all windows} WHILE myWindow <> NIL DO BEGIN DoUpdate(myWindow); {force redrawing window} DoCloseWindow(myWindow); myWindow := FrontWindow; END; gDone := TRUE; {set flag to exit main event loop} END;TheDoQuitprocedure simply closes all windows belonging to the application and then sets the application global variablegDoneto indicate that the user has finished using the application. Recall that the main event loop (Listing 4-4 on page 77) terminates whengDoneisTRUE.
- Note
- The Process Manager automatically deallocates your application partition and closes all windows when your application terminates. As a result, the Venn Diagrammer application could simply have set
gDonetoTRUEin response to the Quit command. However,DoQuitillustrates how to close all windows because your version ofDoCloseWindowmight need to prompt the user to save any unsaved data in document windows currently on the desktop.![]()
Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help