Using the Timer for a Clock

A clock is the most obvious application for the timer, so let’s look at two of them, one digital and one analog.

Building a Digital Clock

The DIGCLOCK program, shown in Example 8-3, displays the current time using a simulated LED-like 7-segment display.

Example 8-3. The DIGCLOCK program.

DIGCLOCK.C /*----------------------------------------- DIGCLOCK.C -- Digital Clock (c) Charles Petzold, 1998 -----------------------------------------*/ #include <windows.h> #define ID_TIMER 1 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("DigClock") ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; wndclass.style ...

Get Programming Windows®, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.