Quantcast
Channel: CodeGuru Forums - C++ and WinAPI
Viewing all articles
Browse latest Browse all 583

[RESOLVED] date & time (non static) in statusbar

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

Viewing all articles
Browse latest Browse all 583

Trending Articles