Click here to Skip to main content
11,413,961 members (76,031 online)
Click here to Skip to main content

Transparent digital clock

, 7 Apr 2003 CPOL
Rate this:
Please Sign up or sign in to vote.
A transparent digital clock program


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 WM_CLOCKTIMETICK message each second.

Brief description

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.

// structure that describes each element
typedef struct _MZDrawObj
    int xPos; // x-coordinate
    int yPos; // y-coordinate
    char cType; // 1: horizontaly, 2: verticaly
} MZDrawObj;

// array for describing each line
MZDrawObj m_obj[4][7];

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[24]) for the first 2 LEDs (hour LEDs) and another one of 60 elements (WORD m_objMin[60]) for the last 2 LEDs (minute LEDs). Each element describes exactly which lines will be drawn (7 bits for each LED).

           0                   0
         *****               *****
        *     *             *     *
      5 *     * 1         5 *     * 1
        *  6  *             *  6  *
         *****               *****
        *     *             *     *
      4 *     * 2         4 *     * 2
        *     *             *     *
         *****               *****
           3                   3  

       1st BYTE            2nd BYTE
  • Function InitDrawObj initializes array elements.
  • Function DrawObj draws the specified m_obj element.
  • Function DrawHour draws the specified m_objHour element (hour LEDs).
  • Function DrawMin draws the specified m_objMin element (minute LEDs).
  • Function DrawDot draws the separator dot between hour leds and minute leds. It is called twice.
  • Function DrawTime does the whole drawing.

Defining window region

Variable HRGN m_hWndRgn defines window region. Function DefineWndRegion reads local time and creates window region. When time changes window region changes as well.

Thread function 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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
Greece Greece
Computer Engineer

Comments and Discussions

Generalupgrade to Visual C++ 2005 Pin
EderAndres, 16-Oct-07 7:05
memberEderAndres16-Oct-07 7:05 
GeneralRe: upgrade to Visual C++ 2005 Pin
merano, 4-Jun-10 5:00
membermerano4-Jun-10 5:00 
GeneralFeatures Request/Suggestions..! Pin
ana_v123, 27-Sep-06 18:17
memberana_v12327-Sep-06 18:17 
AnswerRe: Features Request/Suggestions..! Pin
manos_crete, 27-Sep-06 22:03
membermanos_crete27-Sep-06 22:03 
GeneralRe: Features Request/Suggestions..! Pin
merano, 4-Jun-10 5:18
membermerano4-Jun-10 5:18 
QuestionHow you make it move by dragging Pin
SohailB, 29-Jan-06 22:16
memberSohailB29-Jan-06 22:16 
AnswerRe: How you make it move by dragging Pin
Ice_2k, 16-Nov-06 5:19
memberIce_2k16-Nov-06 5:19 
GeneralWithout TaskBar Icon Pin
Walther Pari, 19-Nov-05 7:04
memberWalther Pari19-Nov-05 7:04 
Question&=? Pin
DavidRobertson, 28-Sep-05 6:27
memberDavidRobertson28-Sep-05 6:27 
AnswerRe: &=? Pin
Ice_2k, 15-Nov-06 23:26
memberIce_2k15-Nov-06 23:26 
GeneralBrilliant, ... simply Brilliant !! Pin
WREY, 6-Jun-03 13:10
memberWREY6-Jun-03 13:10 
GeneralAnother .NET transparent clock Pin
Anonymous, 15-Apr-03 18:02
sussAnonymous15-Apr-03 18:02 
GeneralA few little problems Pin
mwilliamson, 8-Apr-03 14:11
membermwilliamson8-Apr-03 14:11 
1. It could use some configurable options. The colour is almost the same as my desktop and hard to see. Not everyone wants 24 hour time.

2. How do I close it?

3. The task bar button isn't really nescessary because you can't do anything by clicking on it. Its just in the way.
GeneralRe: A few little problems Pin
Robert W., 9-Apr-03 2:03
memberRobert W.9-Apr-03 2:03 
GeneralRe: A few little problems Pin
Ant5, 9-Apr-03 2:39
sussAnt59-Apr-03 2:39 
GeneralRe: A few little problems Pin
e-DJ, 9-Jul-03 3:13
membere-DJ9-Jul-03 3:13 
GeneralRe: A few little problems Pin
manos_crete, 9-Apr-03 8:58
membermanos_crete9-Apr-03 8:58 
GeneralKalo! Pin
Kastellanos Nikos, 8-Apr-03 0:28
memberKastellanos Nikos8-Apr-03 0:28 
QuestionWhy don't you use WM_TIMER? Pin
René Greiner, 7-Apr-03 21:31
memberRené Greiner7-Apr-03 21:31 
AnswerRe: Why don't you use WM_TIMER? Pin
slawek, 8-Apr-03 11:02
memberslawek8-Apr-03 11:02 
GeneralRe: Why don't you use WM_TIMER? Pin
Tommek, 28-Jun-03 3:58
memberTommek28-Jun-03 3:58 
Generalvery nice, but works one hour too erarly Pin
Dieter Hammer, 7-Apr-03 21:14
memberDieter Hammer7-Apr-03 21:14 
GeneralRe: very nice, but works one hour too erarly Pin
Brad Bruce, 8-Apr-03 3:35
memberBrad Bruce8-Apr-03 3:35 
GeneralRe: very nice, but works one hour too erarly Pin
EnderJSC, 17-Aug-05 18:59
memberEnderJSC17-Aug-05 18:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150427.2 | Last Updated 8 Apr 2003
Article Copyright 2003 by manos_crete
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid