By Neil Rhodes, Julie McKeehan
Cover | Table of Contents | Colophon
http://www.massena.com), which
is an indispensable Palm developer resource in its own right.http://www.hewgill.com.
http://www.pendragon-software.com for further
details.
#include <Pilot.h>
#ifdef _ _GNUC_ _
#include "Callback.h"
#endif
#include "HelloWorldRsc.h"
static Err StartApplication(void)
{
FrmGotoForm(HelloWorldForm);
return 0;
}
static void StopApplication(void)
{
}
static Boolean MyFormHandleEvent(EventPtr event)
{
Boolean handled = false;
#ifdef _ _GNUC_ _
CALLBACK_PROLOGUE
#endif
switch (event->eType) {
case ctlSelectEvent: // A control button was pressed and released.
FrmAlert(GoodnightMoonAlert);
handled = true;
break;
case frmOpenEvent:
FrmDrawForm(FrmGetActiveForm());
handled = true;
break;
case menuEvent:
if (event->data.menu.itemID == FirstBeep)
SndPlaySystemSound(sndInfo);
else
SndPlaySystemSound(sndStartUp);
handled = true;
break;
}
#ifdef _ _GNUC_ _
CALLBACK_EPILOGUE
#endif
return handled;
}
static Boolean ApplicationHandleEvent(EventPtr event)
{
FormPtr frm;
Int formId;
Boolean handled = false;
if (event->eType == frmLoadEvent) {
//Load the form resource specified in the event then activate it
formId = event->data.frmLoad.formID;
frm = FrmInitForm(formId);
FrmSetActiveForm(frm);
// Set the event handler for the form. The handler of the currently
// active form is called by FrmDispatchEvent each time it is called
switch (formId) {
case HelloWorldForm:
FrmSetEventHandler(frm, MyFormHandleEvent);
break;
}
handled = true;
}
return handled;
}
static void EventLoop(void)
{
EventType event;
Word error;
do {
EvtGetEvent(&event, evtWaitForever);
if (! SysHandleEvent(&event))
if (! MenuHandleEvent(0, &event, &error))
if (! ApplicationHandleEvent(&event))
FrmDispatchEvent(&event);
} while (event.eType != appStopEvent);
}
DWord PilotMain(Word launchCode, Ptr cmdPBP, Word launchFlags)
{
Err err = 0;
if (launchCode == sysAppLaunchCmdNormalLaunch) {
if ((err = StartApplication()) == 0) {
EventLoop();
StopApplication();
}
}
return err;
}frmLoadEvent
, which is handled by
ApplicationHandleEvent
,
and the frmOpenEvent, which is handled by
MyFormHandleEvent.PilotMain (enter)
StartApplication (enter)
FrmGotoForm(HelloWorldForm) open the HelloWorldForm
StartApplication (exit) returns 0 (proceed)
EventLoop (enter)
EvtGetEvent returns frmLoadEvent (formID
HelloWorldForm)
SysHandleEvent returns false
MenuHandleEvent returns false
ApplicationHandleEvent (enter)
FrmInitForm(HelloWorldForm) load the form
FrmSetActiveForm(frm) activate the form
FrmSetEventHandler(frm, MyFormHandleEvent) set the event handler
ApplicationHandleEvent (exit) returns true
EvtGetEvent returns frmOpenEvent
SysHandleEvent returns false
MenuHandleEvent returns false
ApplicationHandleEvent returns false
FrmDispatchEvent (enter) calls form's event handler
MyFormHandleEvent (enter)
FrmDrawForm(FrmGetActiveForm())
|
System Resources
|
OS 3.0 (>1 MB)
|
OS 2.0 (1 MB; has TCP/IP)
|
OS 2.0 (512 KB; no TCP/IP)
|
|---|---|---|---|
|
System Globals
|
6KB
|
2.5KB
|
2.5KB
|
|
System dynamic allocation |