Clock is a simple program in C++ which shows the current local time in a transparent window.
When time changes the window region changes as well using only the area necessary for displaying time. Instead of setting a timer to read time,
the program uses a thread which posts a
Program displays time in 4 LEDs as shown in the following image:
Each LED consists of 7 lines so we need an array of 4 * 7 = 28 elements to describe each line.
Each element shows the starting position of the corresponding line and how this is going to be
drawn, horizontally or vertically.
typedef struct _MZDrawObj
We also need to represent each hour (0 to 23) and minute (0 to 59) with the
respective lines that will be drawn. In order to achieve this I use an array of
24 elements (
WORD m_objHour) for the first 2 LEDs (hour LEDs) and another one of 60 elements
WORD m_objMin) for the last 2 LEDs (minute LEDs).
Each element describes exactly which lines will be drawn (7 bits for each LED).
* * * *
5 * * 1 5 * * 1
* 6 * * 6 *
* * * *
4 * * 2 4 * * 2
* * * *
1st BYTE 2nd BYTE
InitDrawObj initializes array elements.
DrawObj draws the specified
DrawHour draws the specified
m_objHour element (hour LEDs).
DrawMin draws the specified
m_objMin element (minute LEDs).
DrawDot draws the separator dot between hour leds and minute leds.
It is called twice.
DrawTime does the whole drawing.
Defining window region
HRGN m_hWndRgn defines window region.
DefineWndRegion reads local time and creates window region.
When time changes window region changes as well.
TimeTickThread posts a message each second which calls
OnTimeTick responsible for changing window region and drawing the window.
Using the code
Source code is free for anyone who might find it interested.