Click here to Skip to main content
Licence CPOL
First Posted 7 Apr 2003
Views 105,350
Bookmarked 83 times

Transparent digital clock

By | 7 Apr 2003 | Article
A transparent digital clock program

Introduction

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.

License

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

About the Author

manos_crete

Software Developer (Senior)

Greece Greece

Member

Computer Engineer

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalupgrade to Visual C++ 2005 PinmemberEderAndres6:05 16 Oct '07  
GeneralRe: upgrade to Visual C++ 2005 Pinmembermerano4:00 4 Jun '10  
GeneralFeatures Request/Suggestions..! Pinmemberana_v12317:17 27 Sep '06  
AnswerRe: Features Request/Suggestions..! Pinmembermanos_crete21:03 27 Sep '06  
GeneralRe: Features Request/Suggestions..! Pinmembermerano4:18 4 Jun '10  
QuestionHow you make it move by dragging PinmemberSohailB21:16 29 Jan '06  
AnswerRe: How you make it move by dragging PinmemberIce_2k4:19 16 Nov '06  
GeneralWithout TaskBar Icon PinmemberWalther Pari6:04 19 Nov '05  
Question&=? PinmemberDavidRobertson5:27 28 Sep '05  
AnswerRe: &=? PinmemberIce_2k22:26 15 Nov '06  
GeneralBrilliant, ... simply Brilliant !! PinmemberWREY12:10 6 Jun '03  
GeneralAnother .NET transparent clock PinsussAnonymous17:02 15 Apr '03  
GeneralA few little problems Pinmembermwilliamson13:11 8 Apr '03  
GeneralRe: A few little problems PinmemberRobert W.1:03 9 Apr '03  
GeneralRe: A few little problems PinsussAnt51:39 9 Apr '03  
GeneralRe: A few little problems Pinmembere-DJ2:13 9 Jul '03  
GeneralRe: A few little problems Pinmembermanos_crete7:58 9 Apr '03  
GeneralKalo! PinmemberKastellanos Nikos23:28 7 Apr '03  
QuestionWhy don't you use WM_TIMER? PinmemberRené Greiner20:31 7 Apr '03  
AnswerRe: Why don't you use WM_TIMER? Pinmemberslawek10:02 8 Apr '03  
GeneralRe: Why don't you use WM_TIMER? PinmemberTommek2:58 28 Jun '03  
Generalvery nice, but works one hour too erarly PinmemberDieter Hammer20:14 7 Apr '03  
GeneralRe: very nice, but works one hour too erarly PinmemberBrad Bruce2:35 8 Apr '03  
GeneralRe: very nice, but works one hour too erarly PinmemberEnderJSC17:59 17 Aug '05  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 8 Apr 2003
Article Copyright 2003 by manos_crete
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid