main()
Functionmain()
is called, four parameters are passed:
The function main()
is defined as:
function main ( VAR storage: Handle; blankRgn: RgnHandle; message: Integer; params: GMParamBlockPtr;) : OSErr;
main()
acts as a "dispatcher." It looks at the message passed and calls
a function to perform the task specified in the message. Messages are
passed in a specific order.
On the After Dark disk, we provide a sample main()
function that you can
use as-is. To use our sample main()
function, just write your own
routines DoInitialize()
, DoBlank()
,
DoDrawFrame()
, and DoClose()
as
described briefly in the next section. Link them with main()
to make a
code resource of type 'ADgm
'. Put the resource in a file of type 'ADgm'
and creator 'ADrk
'. Your module is ready to run.
main()
is called repeatedly. In the example code, main()
calls a
different message handling function for each message. The messages are
(in order passed):
main()
calls your function DoInitialize()
. This function
should allocate memory needed by the graphics module and initialize the
module's variables. The graphics module should allocate a Handle to a
block of memory that it will use to hold any variables it needs. It
should then assign it to the parameter storage. No drawing should be
done at this time.
main()
calls your function DoBlank()
. This function should
blank the screen. A banner titling the graphics module or giving credit
to its author might be drawn here. No further drawing should happen.
main()
calls your function DoDrawFrame()
. This function is
responsible for drawing the animation on the screen. It is called
repeatedly and should draw the next frame of the animation sequence.
The basic idea is to "erase old, draw new."
main()
calls your function DoClose()
. At this point, the screen
saver is finished. Any memory allocated should be disposed of and any
other "house cleaning" should be performed. Drawing is allowed, but
your module should return quickly since the user is waiting to regain
control. After Dark handles updating the screen.
main()
| Advanced
| Parameters
| Sound
| Resources
| Hints & Tips
| Further Info