Hi everyone,
I have a program which takes the current system time, and displays it as year, month, day, hour, minute and second. At the moment, it updates the time when you press an 'update' button. However, I want to make it automatically update the time without the user pressing the 'update' button. Here's the program I have now:
Code:
#include <windows.h>
#include <math.h>
#include <cmath>
#include <cstdio>
#include "resource.h"
BOOL CALLBACK ToolDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_UPDATE:
SYSTEMTIME* p_st = new SYSTEMTIME;
GetSystemTime(p_st);
double year = p_st->wYear;
double month = p_st->wMonth;
double day = p_st->wDay;
double hour = p_st->wHour;
double minute = p_st->wMinute;
double second = p_st->wSecond;
char strYear[100];
sprintf_s(strYear,"%0.0f", year);
SetDlgItemText(hwnd, IDC_YEAR, strYear);
char strMonth[100];
sprintf_s(strMonth,"%0.0f", month);
SetDlgItemText(hwnd, IDC_MONTH, strMonth);
char strDay[100];
sprintf_s(strDay,"%0.0f", day);
SetDlgItemText(hwnd, IDC_DAY, strDay);
char strHour[100];
sprintf_s(strHour,"%0.0f", hour);
SetDlgItemText(hwnd, IDC_HOUR, strHour);
char strMinute[100];
sprintf_s(strMinute,"%0.0f", minute);
SetDlgItemText(hwnd, IDC_MINUTE, strMinute);
char strSecond[100];
sprintf_s(strSecond,"%0.0f", second);
SetDlgItemText(hwnd, IDC_SECOND, strSecond);
break;
}
break;
case WM_CLOSE:
EndDialog(hwnd, 0);
break;
default:
return FALSE;
}
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
return DialogBox(hInstance, MAKEINTRESOURCE(IDD_CLOCK), NULL, ToolDlgProc);
}
As you can see, when the user presses IDC_UPDATE, the date and time will update. How could I implement a loop which automatically updates? I could use a while loop in a console program, but that doesn't work here.
Thanks a lot.