1. Display Time & Date In Status Bar
- Posted by Andy <videogamefreak101 at hotmail?co?> Jan 28, 2008
- 598 views
Hey guys, I've been experminting with this, but it won't work. I'm trying to get the time and date to display in a status bar. I know how to and have gotten the status bar split into multiple parts, but I can't get it to show the time and date. Does anyonw know how to?
2. Re: Display Time & Date In Status Bar
- Posted by Greg Haberek <ghaberek at gm?il?com> Jan 28, 2008
- 586 views
- Last edited Jan 29, 2008
Andy wrote: > > I've been experminting with this, but it won't work. I'm trying to get the > time > and date to display in a status bar. I know how to and have gotten the status > bar split into multiple parts, but I can't get it to show the time and date. > Does anyonw know how to? Use a timer to check the date/time every second. Then format this value and insert it into a sub-field using setText( {StatusBarID, FieldNumber}, Text ). Here's a simple example I mocked up. -Greg
-- date-time_demo.exw include Win32Lib.ew without warning constant Main = create( Window, "Date/Time Demo", 0, Default, Default, 640, 480, 0 ), Status = create( StatusBar, "", Main, 0, 0, 0, 0, 0 ), StatusMain = {Status, 1}, StatusDate = {Status, 2}, StatusTime = {Status, 3}, Timer = 1 constant DAYS = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"} procedure setDateTime() sequence dt, ampm, the_date, the_time dt = getLocalTime() ampm = "AM" if dt[5] > 12 then dt[5] -= 12 ampm = "PM" elsif dt[5] = 0 then dt[5] = 12 end if the_date = sprintf( "%s %02d/%02d/%04d", { DAYS[dt[3]+1], dt[2], dt[4], dt[1] } ) the_time = sprintf( "%02d:%02d:%02d %s", { dt[5], dt[6], dt[7], ampm } ) setText( StatusDate, the_date ) setText( StatusTime, the_time ) end procedure procedure Main_onActivate( integer pSelf, integer pEvent, sequence pParams ) setDateTime() setTimer( Main, Timer, 1000 ) end procedure setHandler( Main, w32HActivate, routine_id("Main_onActivate") ) procedure Main_onResize( integer pSelf, integer pEvent, sequence pParams ) sequence rect rect = getClientRect( Main ) setSubFields( Status, {rect[3]-180, -90, -1} ) end procedure setHandler( Main, w32HResize, routine_id("Main_onResize") ) procedure Main_onTimer( integer pSelf, integer pEvent, sequence pParams ) if pParams[1] = Timer then setDateTime() end if end procedure setHandler( Main, w32HTimer, routine_id("Main_onTimer") ) procedure Main_onClose( integer pSelf, integer pEvent, sequence pParams ) killTimer( Main, Timer ) end procedure setHandler( Main, w32HClose, routine_id("Main_onClose") ) WinMain( Main, Normal )
3. Re: Display Time & Date In Status Bar
- Posted by Andy <videogamefreak101 at ho?mail.c?m> Jan 28, 2008
- 583 views
- Last edited Jan 29, 2008
Thanks
4. Re: Display Time & Date In Status Bar
- Posted by OtterDad <otter at ?ul?-moon.com> Jan 30, 2008
- 662 views
i liked Greg's time and date code so much, that i had to borrow it. i created a self-contained include module that will add the date and time piece to the status bar of almost any window by using a single procedure call. before i send it to the contribution page, i welcome enhancements, feedback, flames, etc.
-- time_bar.ew January 30th, 2008 Posted by OtterDad -- self contained auto updating Time and Date fields added to standard Status Bar. -- only needs a single call to Status_Bar_initialize(Status_Bar_handle) to handle the dirty work -- based on Greg Haberek's example code posted to the forum: Date: Mon 28 19:34 -- From: Greg Haberek <ghaberek at gm?il?com> Subject: Re: Display Time & Date In Status Bar include win32lib.ew -- ==================================================================== constant Status_Bar_TimerId = 1 constant days = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"} constant date_year = 1, date_month = 2, date_day = 3, date_hour = 4, date_minute = 5, date_second = 6, date_weekday = 7 object status_junk -- ==================================================================== procedure Status_Bar_pause() doEvents(0) -- play nice with the neighbors and don't hog the cpu end procedure -- ==================================================================== sequence rect procedure Status_Bar_set_sub_fields( integer pSelf, integer pEvent, sequence pParams ) Status_Bar_pause() status_junk = pSelf + pEvent + pParams -- shuts up unused variable warning rect = getClientRect(findParent(pSelf)) -- setSubFields ( integer pID, sequence pPartInfo ) -- Defines the sub-fields in a status bar. -- Category: Attributes -- pID must refer to a status bar control. -- pPartInfo is a list of panel size specifiers for each subfield (a.k.a. panel) in the statusbar. -- Each value in this list can be expressed in one of four ways: -- A positive integer refers to the panels absolute right-hand side pixel position -- A negitive integer less than -1. This refers to a right-hand side position relative to the -- window's right-hand edge. -- An atom > 0 and < 1 refers to the panel's widate_timeh as a fraction of the window's width -- (0.25 means 25% of the window widate_timeh) -- A sequence (containing one integer) refers to the panel's widate_timeh in pixels. If the any -- specification has the value -1, it means that this is the last panel and it extends to the -- right hand edge of the window. -- Example: -- setSubFields(SB, {55, {100}, 0.10, {20},-10,-1}) -- This specifies 6 panels. -- The first one's rightedge is at pixel 55. -- The second is 100 pixels wide. -- The third is 10% of the window width. -- The 4th is 20 pixels wide. -- The 5th is 10 pixels in from the window's RHS. -- The last one extends to the window's edge. setSubFields( pSelf, {rect[3]-170, -80, -1} ) end procedure -- ==================================================================== sequence date_time, ampm, the_date, the_time procedure setDateTime(atom Status_Bar) Status_Bar_pause() date_time = date() ampm = "AM" if date_time[date_hour] > 12 then date_time[date_hour] -= 12 ampm = "PM" elsif date_time[date_hour] = 0 then date_time[date_hour] = 12 end if the_date = sprintf( "%s %02d/%02d/%04d", { days[date_time[date_weekday]], date_time[date_month], date_time[date_day], date_time[date_year] + 1900 }) the_time = sprintf( "%02d:%02d:%02d %s", { date_time[date_hour], date_time[date_minute], date_time[date_second], ampm } ) setText({Status_Bar, 2}, the_date) setText({Status_Bar, 3}, the_time) end procedure -- ==================================================================== procedure Status_Bar_onTimer( integer pSelf, integer pEvent, sequence pParams ) status_junk = pSelf + pEvent + pParams -- shuts up unused variable warning if pParams[1] = Status_Bar_TimerId then setDateTime(pSelf) end if end procedure -- ==================================================================== procedure Status_Bar_onDestroy (integer self, integer event, sequence params)--params is () status_junk = self + event + params -- shuts up unused variable warning killTimer(self, Status_Bar_TimerId) end procedure -- ==================================================================== global procedure Status_Bar_initialize(atom Status_Bar) -- passes in id to status bar to use Status_Bar_pause() Status_Bar_set_sub_fields(Status_Bar, 0, {}) -- split up status bar and add time and date fields setHandler(Status_Bar, w32HResize, routine_id("Status_Bar_set_sub_fields")) -- set handler for resize setDateTime(Status_Bar) -- set the initial display setTimer(Status_Bar, Status_Bar_TimerId, 1000) -- set auto update timer setHandler(Status_Bar, w32HTimer, routine_id("Status_Bar_onTimer")) -- set timer handler setHandler(Status_Bar, w32HDestroy, routine_id("Status_Bar_onDestroy")) -- set handler to kill timer on exit end procedure -- ====================================================================
Yours, OtterDad Don't sweat it -- it's not real life. It's only ones and zeroes. Gene Spafford