At 09:52 AM 7/7/2003 -0700, Ken wrote:
>Hi,
>
>I would like to know how to clear penDownEvents/penUpEvents (maybe
>others).
>
I think if you change your approach slightly, this pen event issue goes
away entirely. See below.
>
>/* Emulate a keydown event */
>static void AddKeyDownEvent(WChar character)
>{
> EventType theEvent;
> MemSet(&theEvent, sizeof(EventType), 0);
>
> /* Create the key down event */
> theEvent.eType = keyDownEvent;
> theEvent.data.keyDown.chr = character;
> theEvent.data.keyDown.keyCode = 0;
> theEvent.data.keyDown.modifiers = commandKeyMask;
>
> /* Add the event to the event queue */
> EvtAddEventToQueue(&theEvent);
>}
As far as exiting your app, you have the right idea with
AddKeyDownEvent( vchrLaunch ). Take a look at
http://www.palmos.com/dev/support/docs/palmos/UserInterface.html#983047
for the official way of doing this, but your approach is essentially the
same. (vchrLaunch == launchChr)
>case frmOpenEvent:
> frmP = FrmGetActiveForm();
> FrmDrawForm(frmP);
> MainFormInit(frmP);
> ShowBitmaps(frmP);
> AddKeyDownEvent(vchrLaunch); //set to close application
> handled = true;
> break;
What you are doing here is having the entire lifecycle of your
application (draw the form, show some bitmaps, enqueue a launchChr to
exit) happen in response to a frmOpenEvent. This is not how the event
loop is designed to work, because you never give any other events a
chance to enter your event loop (penDown events, for example) until
after the break statement -- and before that ever happens, your app has
placed a big, fat launchChr event on the queue which is very likely to
be the next event that gets processed, again because no other events
have had a chance to be received by EvtGetEvent().
The fundamental problem is that you need to allow events to flow through
your event loop freely, without blocking it as you are presently doing.
I would suggest using alarms. If you want to show each bitmap for 1
second, for example, in frmOpenEvent, you could set an alarm to go off
in one second. See
http://www.palmos.com/dev/support/docs/recipes/alarm_mgr.html -- in your
case, your AlarmTriggered() function would do something like:
1) Determine the next bitmap to show; or if it's the last one,
AddKeyDownEvent( vchrLaunch ).
2) display the bitmap
3) set a new alarm to go off in 1 second
In this fashion, you aren't blocking the event loop because alarms
happen asynchronously, so you are letting events flow through your event
loop (even though you aren't handling most of them). I think you'll
find that by doing this, your application will behave much better.
Hope this helps,
-Jeff Ishaq
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/