Monday 28 November 2011

How do you update the title bar in a Windows program? in C programming

How do you update the title bar in a Windows program?

The title bar (or caption bar, as it is often called) can be updated in a Windows program by using the Windows API function SetWindowText(). The SetWindowText() function takes two parameters. The first parameter is the handle to the window, and the second parameter is the new title you want to display on the window.

One reason you might want to take this action is to provide your users with the current date and time on the title bar. This task can be accomplished with the following code:

char* szAmPm = “PM”;
char szNewCaption[200];
struct tm* tmToday;
time_t lTime;
time(&lTime);
tmToday = localtime(lTime);
wsprintf(szNewCaption,
“My Application - %02d/%02d/%02d %02d:%02d:%02d %s”,
tmToday->tm_month, tmToday->tm_mday, tmToday->tm_year,
tmToday->tm_hour, tmToday->tm_min,
tmToday->tm_sec, szAmPm);
SetWindowText(hwnd, szNewCaption);
Of course, you probably will want to set up this code in some sort of timer event loop so that the title is
updated every second (or minute).

Cross Reference:

None

No comments:

Post a Comment