That's almost the right way. You need to do this, too:
>eventType newEvent;
MemSet(&newEvent, sizeof(newEvent), 0); // init all members to 0
>newEvent.eType = appStopEvent;
>EvtAddEventToQueue(&newEvent);
>// eventHandled = true; // not needed
HOWEVER, you shouldn't have a DONE button for your application.
That's not how the Palm 'user convention' works. On Palm, the user
expects to be in one application until (s)he chooses to be in
another. You app will 'shutdown' as a result of the user's starting a
NEW application. It shouldn't just 'shutdown' on its own EXCEPT in
the condition that you have an error initializing the app. In that
case, it's OK to 'exit' back to whatever was happening.
Alan Pinstein
Synergy Solutions, Inc.
http://www.synsolutions.com
1-800-210-5293
> > > 1) is there a function that calls the shutdown event?
> > ie, if i'm
> > > looping through my event loop, what can i call or what
> > condition must i
> > > meet to cause the application to shut down?
> >
> > The AppStopEvent may be generated by a couple of possible system
> > events (like pressing a hardware button or when launching another
> > application).
> >
> > On the other hand you just can just "break" from your event loop.
> > Your application is over as soon as you leave PilotMain.
> >
> > You also can enqueue an AppStopEvent, but you rarely want that.
>
>Why would enqueueing an AppStopEvent be a bad idea ? I just worked out my
>first app, and have provided a 'Done' button. When it is tapped, I have some
>code in my FormHandler
>
>eventType newEvent;
>newEvent.eType = appStopEvent;
>EvtAddEventToQueue(&newEvent);
>eventHandled = true;
>
>after which I exit the formHandler. It works for my very simple app (not
>much more than a 'Hello World'). I had some thoughts when coding this
>however.
>The SDK reference doesn't explain how EvtAddEventToQueue works with memory.
>I assumed it takes a copy of the event pointed at, so I could use an auto
>variable for the event information. This works, but maybe just by accident.
>On the other hand, if I have to allocate the new event, who releases it, and
>when ?
>The third possibility I saw was to re-use the event that triggered my
>formHandler in the first place, but I expected that event to be freed by
>someone somewhere unless I did something exotic.
>
>So the question remains: is this the right way to enqueue the AppStopEvent
>(or any other event as far as I am concerned), and if it is, where are the
>pitfalls ?
>
>Sincerely,
>Jan Vereecke