The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: elmo on December 26, 2010, 05:16:21 AM

Title: how to show system time dynamically?
Post by: elmo on December 26, 2010, 05:16:21 AM
I use the following code to show system time. It success. But the time in label is static.
Can we show it dynamically?

      invoke GetLocalTime, addr systime
      invoke GetDateFormat, NULL, NULL, ADDR systime, ADDR DateFormat, ADDR szDate, 40
      invoke GetTimeFormat, NULL, NULL, ADDR systime, ADDR TimeFormat, ADDR szTime, 20
      invoke lstrcpy, addr strText, SADD("Date: ")
      invoke lstrcat, addr strText, ADDR szDate
      invoke lstrcat, addr strText, ADDR szCrLf
      invoke lstrcat, addr strText, SADD("Time: ")
      invoke lstrcat, addr strText, addr szTime
      invoke SendMessage,hLabel,WM_SETTEXT,0,ADDR strText
      invoke UpdateWindow,hLabel
Title: Re: how to show system time dynamically?
Post by: Tight_Coder_Ex on December 26, 2010, 06:59:43 AM
You have to incorporate your code in a timer event.
Title: Re: how to show system time dynamically?
Post by: MichaelW on December 26, 2010, 09:41:03 AM
Basically, you can set up a timer with  SetTimer (http://msdn.microsoft.com/en-us/library/ms644906(VS.85).aspx), specifying an appropriate time-out value and timer identifier, and then catch the timer event in a WM_TIMER handler in your window procedure, or in a  TimerProc (http://msdn.microsoft.com/en-us/library/ms644907(VS.85).aspx) callback.