-
December 13th, 2012, 08:19 PM
#1
[RESOLVED] date & time (non static) in statusbar
hi all,
I'm trying to place the date and time in my statusbar, but the time does not change and remains static, I think I need a loop or something, I google it and found several ways to get time from my system, and this is the only one that works with 12h am-pm
Code:
//add time.h
struct tm newtime;
char am_pm []="am";
char t_buf [26];
__time64_t long_time;
errno_t err;
_time64 (&long_time);
err = _localtime64_s (&newtime, &long_time);
if (newtime. tm_hour>12) strcpy_s (am_pm, sizeof (am_pm),"pm");
if (newtime. tm_hour>12) newtime.tm_hour -=12;
if (newtime. tm_hour==0) newtime.tm_hour =12;
err = asctime_s (t_buf,26,&newtime);
wsprintf (t_buffer,"%.19s %s",t_buf, am_pm);
SendMessage (h_statusbar, SB_SETTEXT, 0, (LPARAM) t_buffer);
Code:
//more optimized
char am_pm []="am";
SYSTEMTIME slt;
GetLocalTime (&slt);
if (slt.wHour>12) strcpy_s (am_pm, sizeof (am_pm),"pm");
if (slt.wHour>12) slt.wHour -=12;
if (slt.wHour==0) slt.wHour =12;
wsprintf (t_buffer,
"%02d/%02d/%d @ %02d:%02d:%02d %s",
slt.wDay, slt.wMonth,slt.wYear,
slt.wHour,slt.wMinute,slt.wSecond,
am_pm);
SendMessage (h_statusbar, SB_SETTEXT, 0, (LPARAM) t_buffer);
maybe is simple but can not get a function for that, I do not want to do it for me, just guide me or the name of a function and excuse my language, I'm from latin america ^^
regards
Last edited by v_nom70; December 13th, 2012 at 09:18 PM.
-
December 13th, 2012, 09:19 PM
#2
Re: date & time (non static) in statusbar
Add a timer component and put your code in the timer tick event. I think I saw an example of just this in VS walkthroughs.
You don't want to put it in a loop or you won't be able to do anything else!
-
December 13th, 2012, 09:50 PM
#3
Re: date & time (non static) in statusbar
Humm.. I forgot to say, do not use C# or MFC, I use vs2010 winapi 32 + mysql, but thank you wrote, I found WM_TIMER and SetTimer trying to find a solution.
-
December 13th, 2012, 10:07 PM
#4
Re: date & time (non static) in statusbar
Solved... thank you very much!!!
Code:
// WinMain
SetTimer(hwnd, ID_MY_TIMER, 1000,(TIMERPROC) NULL);
// WndProc
case WM_TIMER:
switch (wp_wparam)
{
case ID_MY_TIMER:
const char *dia[]={"Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sabado"};
char am_pm []="am";
SYSTEMTIME slt;
GetLocalTime (&slt);
if (slt.wHour>12) strcpy_s (am_pm, sizeof (am_pm),"pm");
if (slt.wHour>12) slt.wHour -=12;
if (slt.wHour==0) slt.wHour =12;
wsprintf (t_buffer,
"%s %02d/%02d/%d @ %02d:%02d:%02d %s",
dia[slt.wDayOfWeek],
slt.wDay, slt.wMonth,slt.wYear,
slt.wHour,slt.wMinute,slt.wSecond,
am_pm);
SendMessage (h_statusbar, SB_SETTEXT, 0, (LPARAM) t_buffer);
break;
}
break;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|