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
// 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.
there are much better ways to implement a stopwatch tho :)
--
// Aaron Ardiri
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/