main()
must be the first routine in
your graphics module code resource. main()
is passed a sequence of
messages to direct its behavior:
Initialize
It is important to understand why variables might be stored this way. In many development systems a code resource cannot have global variables. If your development system does not support globals, a structure must be declared and memory allocated as in our example code. The fields of this structure can be any data type.
Remember, the storage handle is not locked down when it is passed to
main()
so it is the module's responsibility to lock the handle when
necessary, and unlock it before returning.
Blank
DrawFrame
message.
DrawFrame
Close
ButtonMessage
ButtonMessage
is passed to main()
. The value of
ButtonMessage
depends
on which button was hit. The value of each button is distinct and is
defined in a resource. All messages with a value of 8 or greater are
button messages. In the example code, ButtonMessage
is handled by the
DoSetup()
function.
The graphics module could use this kind of message to open a dialog box allowing the user to set values not easily handled by sliders, menus, or check boxes. A button could allow the user to select a color from the "Color Picker" or choose a picture from a scrapbook, for example.
ModuleSelected
To receive this message, add the 'Cals' resource to your module and set it as described in the "Graphics Module Resources" section.
DoHelp
As above, to receive this message, add a 'Cals' resource to your module and set it as described in the "Graphics Module Resources" section.
noErr
. There are two
conditions where this will not be the case:
DoInitialize()
a graphics module usually attempts to allocate
memory. If there is an error in allocating the storage, the graphics
module should return the value ModuleError
(defined as integer value
-1). If errors occur on later calls, the graphics module should dispose
of any memory allocated and return this error value to After Dark.
RestartMe
(defined as the integer value 1) tells
After Dark to restart the graphics module immediately with an Initialize
message without an intervening Close
message. The graphics module
should close itself before returning this value. The graphics module
might use this service if it finds that it has been passed changing
parameters that require it to reallocate storage.
ImDone
(defined as the integer value 2) tells After
Dark to take over the drawing. The graphics module uses this when it is
done drawing but wants something else to happen on the screen.
RefreshResources
(defined as the integer value 3)
updates all sliders, buttons, check boxes, menus, and text strings in
the Control Panel to their values in the module's resource file. This
allows you to change the items in a menu or the values of text strings
in your module's resource file and have these changes immediately
reflected in the Control Panel. This value should only be returned in
response to ButtonMessage
or ModuleSelected
.
main()
| Advanced
| Parameters
| Sound
| Resources
| Hints & Tips
| Further Info