Aaron Ardiri wrote:
On 7/29/06, Luc Le Blanc <[EMAIL PROTECTED]> wrote:
I'm trying to setup a stopwatch-like dialog where I have a Start/Stop
button, and an OK button. When the Start button is hit, I start
displaying elapsed time until the Stop button is hit or the Datebook
hardware button is depressed. My problem is handling the OK button (to
leave the dialog even while the timer is running) and events like a
vchrLaunch keyDownEvent (to leave the application). None of my many
attempts fully succeeded. Either the vchrLaunch is ignored, or the OK
button, or both. My latest attempts goes like this. What's wrong?


case ctlEnterEvent :

    if ( event->data.ctlEnter.controlID != StartButton )
        return false;

    // update display every 0.1 s
    UInt32 timeout = SysTicksPerSecond() / 10L;

    do
    {
        EvtGetEvent( &loopEvent, timeout );

        if ( loopEvent.eType == nilEvent )
            // update elapsed time display

There is a "continue;" missing here


        // when entering Stop button, leave loop
        else if ( loopEvent.eType == ctlEnterEvent )
        {
            if ( loopEvent.data.ctlEnter.controlID == StopButton )
                break;
        }

        // if keyDownEvent, leave loop on Datebook key tap
        else if ( loopEvent.eType == keyDownEvent )
        {
            if ( loopEvent.data.keyDown.chr == vchrHard1 )
                break;
        }

        // let form handle pen events
        else if ( ( loopEvent.eType == penDownEvent ) ||
                  ( loopEvent.eType == penMoveEvent )||
                  ( loopEvent.eType == penUpEvent )
        {
            FrmDispatch( loopEvent );
            continue;
        }

        // let OS handle other events
        return SysHandleEvent( &loopEvent );

    } while ( time < 30.0 );    // stop loop after 30s

    // display elapsed time-related data

    handle = true
break;



eek. thats some nasty code :)

        // let OS handle other events
        return SysHandleEvent( &loopEvent );

you know this will break your while loop? if you just want the system to
handle it; dont have the "return" there in the front and your timer loop
will stay operational.

I know this will exit the loop; I do that in order to leave when getting events such as a vchrLaunch, vchrAutoOff or anything else that should stop my program.



there are much better ways to implement a stopwatch tho :)


My purpose here is to display time elapsed during the fall of a rock in a cave pit, so as to display estimated depth. Displaying the time as it goes is a little luxury, I could as well display elapsed time only when the Stop button is hit, but I felt it gave more feedback.

Design suggestions are welcome ;)



--
Luc Le Blanc

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

Reply via email to