ThuNguyet,

I'd do as your last sentence: One place to handle the event, check for 
active form.

Huy T. Phan

______________________________________________________________

Message: 2
    Date: Thu, 18 Apr 2002 10:19:38 -0700 (PDT)
    From: ThuNguyet Nguyen <[EMAIL PROTECTED]>
Subject: Handle user events, please help.

Hello all,

In my Palm program, I have 5 forms A, B, C, D, E. The user can move between 
forms.

The main loop is as below:

static void AppEventLoop(void)
{
    UInt16 error;
    EventType event;

    do {
       EvtGetEvent(&event, evtWaitForever);
       if (! SysHandleEvent(&event))
          if (! MenuHandleEvent(0, &event, &error))
             if (! AppHandleEvent(&event))
                if (!AppHandleUserEvent(&event))
                   FrmDispatchEvent(&event);

    } while (event.eType != appStopEvent);
}

//snip code
static Boolean AppHandleEvent(EventPtr eventP)
{
    UInt16 formId;
    FormPtr frmP;

    if (eventP->eType == frmLoadEvent)
       {
       // Load the form resource.
       formId = eventP->data.frmLoad.formID;
       frmP = FrmInitForm(formId);
       FrmSetActiveForm(frmP);

       // Set the event handler for the form.  The handler of the currently
       // active form is called by FrmHandleEvent each time is receives an
       // event.
       switch (formId)
          {
          // ...
          case BForm:
             FrmSetEventHandler(frmP, BFormHandleEvent);
             break;
          }
          // ...
       }
}

The program generates some user events. I need to have each certain form 
handles some specific
events.

For example, I need to have form B handles user event X and Y. So, I put to 
code to handle event X
and Y in BFormHandleEvent().
To prevent the events from not being handled when user go to other form, I 
also put the code to
handle event X, Y (do some general things but not update the active form B) in
AppHandleUserEvent().

I did set handled to true after I handle an user event and the event should 
be out of the queue
event after it is processed. Is that right?

As the flow of the program, I think that the code inside BFormHandleEvent() 
will be called first
if form B is the active form, if user goes to other form, the events will be 
handle in
AppHandleUserEvent() but it doesn't happen that way. The event X and Y are 
"always" handled in
AppHandleUserEvent() no matter which form is actived.

If I want Form B handles the events X and Y, I have to take out the code in 
AppHandleUserEvent().
If I do that, and if the event occurs when Form B is not actived, then there 
is no code to handle
those events.

Please tell me what I did wrong. How can I make a form handles certain events?

Should I put all the code to handle user events in AppHandleUserEvent() and 
check for active form
to do proper things?

Thank you for any help or suggestion.

tnn

____________



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to