1. [WIN] Re: how to display a clock in a window?

Yan,

Here's a better way to make a clock in a window; it uses a timer to *get*
the time from the system clock every second;  the advantage is that the
timer itself may sometimes *skip* "ticks" when various things happen in
Windows, so a clock based on incrementing the ticks received from the timer
may become wrong.  But the system time is always(?) correct.  So in this
version, the routine may on occasion neglect to get the time for some tick
or another, but the time it next returns would be correct.

It's in 24 hour format.

Dan

<code follows:>
--
-- Better Simple Clock
-- gets actual time (in 24 hour format)

include win32lib.ew
without warning

constant ClockWin =
    create( Window, "Simple Clock", 0, Default, Default, 250, 100, 0 )

constant MyTimer    = 1
----------------------------------------------------------------------------
-
sequence TimeAndDate, theTime
TimeAndDate = date() -- includes both time and date info

integer seconds,minutes,hours

hours = TimeAndDate[4]
minutes = TimeAndDate[5]
seconds = TimeAndDate[6]

----------------------------------------------------------------------------
-
procedure onTimer_ClockWin( integer timerId )

   -- get the time every second
    TimeAndDate = date()

    hours = TimeAndDate[4]
    minutes = TimeAndDate[5]
    seconds = TimeAndDate[6]

    -- force an onPaint event
    repaintWindow( ClockWin )

 end procedure

----------------------------------------------------------------------------
-
procedure onPaint_ClockWin( integer x1, integer y1, integer x2, integer y2 )

    -- display the new clock time:
    theTime=sprintf("%02d:%02d:%02d",{hours,minutes,seconds})
    setPosition(ClockWin,30,30)
    wPuts(ClockWin,theTime)

end procedure


----------------------------------------------------------------------------
-
procedure onOpen_ClockWin()

    -- activate the timer to tick each second (1000 ms)
    setTimer( ClockWin, MyTimer, 1000 )
    setFont(ClockWin, "Arial", 15, Bold)

end procedure

onOpen[ClockWin]    = routine_id( "onOpen_ClockWin" )
onTimer[ClockWin]   = routine_id( "onTimer_ClockWin" )
onPaint[ClockWin]   = routine_id( "onPaint_ClockWin" )


WinMain( ClockWin, Normal )

<code ends>
----- Original Message -----
From: "YanYanCup YanYanCup" <yanyancup at HKEM.COM>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Thursday, October 12, 2000 4:25 AM
Subject: how to display a clock in a window?


> i want to display a clock in the window that i create but i cannot do
that! Euphoria said that my program is over 300 statment, therefore i don't
know what happen!
> please help to check the code(many of them are copy from Brett Pantalone's
stopwatch timer) or  suggest some suggestion of how to write it and display
in a window thanks ^0^
>
>
> --cute at here
> include win32lib.ew
> without warning
> integer milliseconds, seconds, minutes, hours
> milliseconds=0
> seconds=0
> minutes=0
> hours=0
> sequence timer1
> constant new_win=create(Window,"time",0,100,100,300,300,0)
> openWindow(new_win,Normal)
> setTimer(new_win, 1, 1000 )
>
> procedure onTimer_timerWin( integer timerId )
> -- This procedure runs once every second.
>
>     -- increment the timer
>     seconds = seconds + 1
>     if seconds > 59 then
>        seconds = 0
>        minutes = minutes + 1
>        if minutes > 59 then
>           minutes = 0
>           hours = hours + 1
>        end if
>     end if
>
>
>     timer1=sprintf("%02d:%02d:%02",{hours,minutes,seconds})
>     setPosition(new_win,30,30)
>     wPuts(new_win,timer1)
>     -- force an onPaint event
>     --repaintWindow(Cute_light)
>
> end procedure
>
> onTimer[new_win] = routine_id( "onTimer_timerWin" )
> i have try ^^^^ 1 at here, but still can't display a clock...
> WinMain(new_win,Normal)
>
> --cute at here
>
> YanYanCup
> _____________________________________________________
> Sent by Hong Kong E-Mail at http://www.hkem.com
> It's free. It's easy. Sign up your account Now!

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu