tips
[Top] [All Lists]

Handling the core AppleEvents

To: "REALbasic Tips" <REALbasic-tips at lists dot realsoftware dot com>
Subject: Handling the core AppleEvents
From: Geoff Perlman <geoff at realsoftware dot com>
Date: Mon, 31 Jan 2000 14:57:44 -0600
When you restart or shutdown your Macintosh, the Finder tells each running application to quit. If the application knows to watch for this message, it can respond to it and quit. If it doesn't, your Macintosh won't restart or
shutdown until the user manually quits the application. Eventually, the
Finder will decide not to restart or shutdown at all if the user doesn't
respond within a given period of time. This message is called an AppleEvent and there are three AppleEvents that every application made with REALbasic
should respond to appropriately. They are open, print and quit. The most
important of these is open.

Getting your REALbasic-made application to respond to these three
AppleEvents is quite easy. You simply need to add an Application class to your project (if you don't already have one) and add a few lines of code to its HandleAppleEvent event. To add an Application class to your project and
put in the AppleEvent code, do this:

1. Add a new class to your project and set its super property to
"Application" and its name to "app".

2. Put this code in the HandleAppleEvent event of the app class:

if eventClass = "aevt" then
Select Case eventID
case "odoc" //open
case "pdoc" //print
case "quit" //quit
return true
quit
End Select
end if

The above example handles the quit event only put includes placeholders for
the open and print events. "aevt" is the event class for the core
AppleEvents. "odoc" is the event that is sent to your app when another
application (like the Finder) wants your application to open a document,
"pdoc" is the event that sent for printing and "quit" for quitting. If your application is going to handle of these events, it needs to return true in the HandleAppleEvent event so that the application that sent the event knows your application is going to handle it. Notice that for the quit AppleEvent, true is returned and the quit command is then called. When your application receives a quit AppleEvent, it should do whatever it does when the chooses
Quit from the File menu.
--

Geoff Perlman
REAL Software, Inc.
http://www.realsoftware.com
mailto:geoff at realsoftware dot com


 - - - - - - - - - -
For list commands, send "Help" in the body of a message to
<requests at lists dot realsoftware dot com>



<Prev in Thread] Current Thread [Next in Thread>
  • Handling the core AppleEvents, Geoff Perlman <=