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

Yan,

In your line:
add a "d" after the third "%02"

And try this code instead (from the timer example with Win32Lib):

-- <code begins:>
--
-- Simple Clock

include win32lib.ew
without warning

constant TimerWin =
    create( Window, "Timer Window", 0, Default, Default, 200, 100, 0 )

constant MyTimer    = 1

----------------------------------------------------------------------------
-
integer seconds,minutes,hours

seconds=0
minutes=0
hours=0
sequence timer1
----------------------------------------------------------------------------
-
procedure onTimer_TimerWin( integer timerId )


    -- increment the clock
    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

    -- force an onPaint event
    repaintWindow( TimerWin )


end procedure

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

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

end procedure


----------------------------------------------------------------------------
-
procedure onOpen_TimerWin()

    -- activate the timer to tick each second (1000 ms)
    setTimer( TimerWin, MyTimer, 1000 )

end procedure

onOpen[TimerWin]    = routine_id( "onOpen_TimerWin" )
onTimer[TimerWin]   = routine_id( "onTimer_TimerWin" )
onPaint[TimerWin]   = routine_id( "onPaint_TimerWin" )


WinMain( TimerWin, Normal )

--<code ends>

Dan

----- 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