> Summary: When handling the sysAppLaunchCmdDisplayAlarm launch code, how
can
> I find out if my application is the "running" application, that is, the
one
> that the user was using when the alarm went off?

I didn't receive any advice about the preferred way to find out if my app
was the running app when my alarm went off, so I had to invent something.
The method below works (at least in OS 3.5), but relies upon "chance" to
work.  That is, it first sees if the active form has the same ID as any of
the forms in my app.  If it does, then it compares the title of the active
form to the title of that Form ID in my app.  If it matches, then it is
assumed that it really is my form, and not another program using the same ID
and title combination.

It's not the best method, so if anyone has suggestions for a more robust
solution, I'd appreciate hearing it.

Boolean IsMyAppActive(           // return true if app is running
    FormType * pActiveForm)    // [in] the active form

    {
    FormType * pMyForm = NULL;
    FormTitleType * pTitle = NULL;
    const Char * MyTitle = NULL;
    const Char * ActiveTitle = NULL;
    UInt16 ActiveID = 0;
    UInt16 i;

    // If there isn't an active form, then we must assume that
    // we are not the active application.

    if (pActiveForm == NULL)
        {
        return false;
        }

    // See if the ID of the active form matches one of our form
    // IDs.  If it doesn't, then we can say with confidence that
    // we are not the active application.

    ActiveID = FrmGetFormId(pActiveForm);

    if ( (ActiveID != MainForm) &&
         (ActiveID != AboutForm) )
        {
        return false;
        }

    // If here, then ActiveID matches one of our own forms.
    // That doesn't mean that it really is one of our forms,
    // though.  The next thing to try is to match the title
    // of the form.  If it does match our title, then we're
    // more sure that it really is our form.
    //
    // Note that ResLoadForm doesn't initialize all pointers,
    // so as a result, FrmGetTitle() complains that the form
    // isn't valid.  (Never-the-less, the title is there.)
    //
    // As a result, rather than using FrmGetTitle(), I scan
    // through the structure myself.

    pMyForm = ResLoadForm(ActiveID);
    if (pMyForm == NULL)
        {
        // Huh.  Well, assume that it is us.
        return true;
        }

    for (i = 0; i < pMyForm->numObjects; i++)
        {
        if (pMyForm->objects[i].objectType == frmTitleObj)
            {
            pTitle = pMyForm->objects[i].object.title;
            MyTitle = pTitle->text;
            break;
            }
        }

    if (MyTitle == NULL)
        {
        // We didn't find the title in this form.
        return true;
        }

    ActiveTitle = FrmGetTitle(pActiveForm);
    return (StrCompare(MyTitle, ActiveTitle) == 0);
    }




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

Reply via email to