Click here to Skip to main content
12,889,437 members (48,000 online)
Click here to Skip to main content
Add your own
alternative version


59 bookmarked
Posted 19 Jan 2008

BigClock with Transparent Background

, 19 Jan 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
BigClock with Transparent Background based on the 7 segment LCD


This is a transparent desktop clock based on the 7 segment LCD. I published a seven segment LCD article a while ago, and based upon that control, I quickly slapped together a transparent desktop clock. It is with pleasure I am sharing it with The Code Project community.


One of my colleagues walked by and was very impressed with BigClock. He immediately requested a copy for himself, and I see it on his screen all the time.


Using the Code

The 7 segment code worked without modification in a transparent environment. However I added a class interception snippet to erase the CStatic frames at runtime. This way, the controls in the dialog editor can have the 'sunken' style to see how big the controls are and where they are. This makes it easier to design the form for the control. Here is the code that does this:

// Call this when the control is painted the first time

// The interception is archived by `maintaining a class variable called 

// 'firstpaint'

    firstpaint = true;


    firstpaint = false;

One would ask why do this in OnPaint? Well, the CStatic and CWnd based controls do not receive many messages. This way, we are taking advantage of the only message that even static controls cannot avoid: painting.


I added 12/24 hour switch, seconds display on/off switch and small/medium/large size control. I also added AutoStart, OnTop, and window placement persistence.


Medium size setting on top of the silver theme:


The small setting is ideal for a clock that is always on screen.


This is how BigClock looks like on my development machine, in the upper right corner.


BigClock on large setting with the setup/config dialog:


Points of Interest

The code snippet for creating transparent dialogs is as follows:

// These defines are not in W32 SDKs

#define WS_EX_LAYERED     0x00080000
#define LWA_COLORKEY     1     // Use a color as the transparency color.

// Into the global space or class space insert:

//  Function pointer for the layering API is in User32.dll

typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)
            (HWND hWnd, COLORREF cr, BYTE bAlpha, DWORD dwFlags);

lpfnSetLayeredWindowAttributes g_pSetLayeredWindowAttributes = NULL;

HMODULE hUser32 = GetModuleHandle(_T("USER32.DLL"));
    g_pSetLayeredWindowAttributes = (lpfnSetLayeredWindowAttributes)
                        GetProcAddress(hUser32, "SetLayeredWindowAttributes");

// Into the init dialog insert:

    // Set layered style for the dialog

    SetWindowLong(m_hWnd, GWL_EXSTYLE, 
        GetWindowLong(m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);

        // Use green (0,255,0) as transparency color

        g_pSetLayeredWindowAttributes(m_hWnd, RGB(0, 255, 0), 0, LWA_COLORKEY);
// After this initialization, anything painted in green will be transparent 


  • 20th January, 2008: Initial version, added taskbar hiding


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) Self Employed
United States United States
C, C++, DSP, Graphical Apps, UNIX, LINUX

You may also be interested in...

Comments and Discussions

GeneralThanks Pin
Nud3l3-Nov-10 3:29
memberNud3l3-Nov-10 3:29 
GeneralGreat Big Clock Pin
Mudhi27-Feb-08 6:48
memberMudhi27-Feb-08 6:48 
GeneralRe: Great Big Clock Pin
lxa52016-Sep-10 23:57
memberlxa52016-Sep-10 23:57 
some question:
1. when I right double Click the last LCD, the window coundnot close.
2. I dont show Second, Drag the Window, the Range is still show
QuestionQuestion Pin
lxa52016-Sep-10 23:58
memberlxa52016-Sep-10 23:58 
GeneralNicely done.. minor suggestions Pin
Chamadness24-Jan-08 19:41
memberChamadness24-Jan-08 19:41 
GeneralNice Clockage Pin
Julian Nicholls22-Jan-08 3:39
memberJulian Nicholls22-Jan-08 3:39 
GeneralNice work! Pin
Member 329225720-Jan-08 9:58
memberMember 329225720-Jan-08 9:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 20 Jan 2008
Article Copyright 2008 by PeterGlen
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid