如果你有一些Windows消息处理和Win32 API的经验,这应该让你开始。
LRESULT WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT r;
char szBuffer[200];
static int count = 120;
int seconds = 0;
int minutes = 0;
int hours = 0;
switch (message) {
case WM_CREATE:
// create a 1 second timer
SetTimer (hwnd, ID_TIMER, 1000, NULL);
return 0;
case WM_PAINT:
if(count > 0)
{
hdc = BeginPaint (hwnd, &ps);
GetClientRect (hwnd, &r);
hours = count/3600;
minutes = (count/60) % 60;
seconds = count % 60;
wsprintf (szBuffer, "Hours: %d Minutes: %d Seconds: %d", hours, minutes, seconds);
DrawText (hdc, szBuffer, -1, &r, DT_LEFT);
EndPaint (hwnd, &ps);
}
else
{
SendMessage (hwnd, WM_CLOSE, 0, 0L)
}
return 0;
case WM_TIMER:
count--;
InvalidateRect (hwnd, NULL, TRUE);
return 0;
case WM_DESTROY:
KillTimer (hwnd, ID_TIMER);
PostQuitMessage (0);
return 0;
} /* end switch */
}
下面是使用计时器上一个很好的链接:
Using Timers
查看大图或全屏显示? – Grant 2009-01-27 18:09:39