1. Win32Lib Timer Stuff
- Posted by "C. K. Lester" <euphoric at cklester.com> Sep 30, 2003
- 442 views
Derek, other Win32Lib gurus, I wanted to create a tiny app that would check my internet connection and tell me whether it was up or not. Winstar went down for a few hours today (all over the country, apparently), and I hastily created a Win32Lib app to ping some server and tell me whether it connected or not. Actually, I never got that far because I wanted it to check every 5 seconds but didn't know how to capture a timer event. setTimer() still refers to onTime, but I know that can't be right... Help! :) -ck
2. Re: Win32Lib Timer Stuff
- Posted by Derek Parnell <ddparnell at bigpond.com> Sep 30, 2003
- 441 views
----- Original Message ----- From: "C. K. Lester" <euphoric at cklester.com> To: "EUforum" <EUforum at topica.com> Subject: Win32Lib Timer Stuff > > > Derek, other Win32Lib gurus, > > I wanted to create a tiny app that would check my internet connection and > tell me whether it was up or not. Winstar went down for a few hours today > (all over the country, apparently), and I hastily created a Win32Lib app to > ping some server and tell me whether it connected or not. Actually, I never > got that far because I wanted it to check every 5 seconds but didn't know > how to capture a timer event. setTimer() still refers to onTime, but I know > that can't be right... > > Help! :) > Here is a sample program ... ------------------------- include win32lib.ew without warning ------------------------------------------------------------------------ -- make a really small window with just the caption to put the time into: constant ClockWin = create( Window, " Clock", 0, 0, 0, 150, 0, { WS_DLGFRAME, WS_SYSMENU} ) -- Define a timer id, can be any number. constant MyTimer = 1 --------------------------------------------- procedure ShowTime() --------------------------------------------- sequence TimeAndDate, theTime integer seconds,minutes,hours TimeAndDate = date() -- returns both time and date info hours = TimeAndDate[4] minutes = TimeAndDate[5] seconds = TimeAndDate[6] -- display the new clock time: theTime=sprintf("%02d:%02d:%02d",{hours,minutes,seconds}) setText(ClockWin," " & theTime) -- puts a space at left of caption 1st end procedure -- set the timer to tick once a second when window opens: --------------------------------------------- procedure onOpen_ClockWin(integer self, integer event, sequence parms) --------------------------------------------- -- activate the timer to tick each second (1000 ms) setTimer( ClockWin, MyTimer, 1000 ) setFont(ClockWin, "Arial", 15, Bold) ShowTime() end procedure ------------------------------------------------------------------- -- get the ACTUAL time every second, & show it in caption: --------------------------------------------- procedure onTimer_ClockWin( integer self, integer event, sequence parms) --------------------------------------------- ShowTime() end procedure -- Start running the app. setHandler(ClockWin, w32HOpen, routine_id( "onOpen_ClockWin" )) setHandler(ClockWin, w32HTimer, routine_id( "onTimer_ClockWin" )) WinMain( ClockWin, Normal ) ------------------------- -- Derek