Click here to Skip to main content
Email Password   helpLost your password?

Introduction

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.

Background

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.

medshot_blue.jpg

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'

Clcd7::Clcd7()
    {
    .....
    firstpaint = true;
    .....
    }

if(firstpaint)
    {
    //TRACE("firstpaint\r\n");
    firstpaint = false;
      ModifyStyleEx(WS_EX_STATICEDGE | WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE, 0);
    }

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.

Features

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.

Screens

Medium size setting on top of the silver theme:

bigclock

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

smallshot.jpg

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

smabb_used.jpg

BigClock on large setting with the setup/config dialog:

bigclock.jpg

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);

   if(g_pSetLayeredWindowAttributes)
        {
        // 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 

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralGreat Big Clock
Mudhi
7:48 27 Feb '08  
Love at first glance, I can now study how to add alarm feature on it. Big Grin

Thanks!
GeneralNicely done.. minor suggestions
Chamadness
20:41 24 Jan '08  
Thanks for sharing such a nice work.
I have a minor suggestion: why not allow the user to choose the overall "clock size" == width x height?
I mean you can easily scale out/in your LCD digits..
Again thanks!

To code, or not: Too code!

GeneralNice Clockage
Julian Nicholls
4:39 22 Jan '08  
I love it, but I have just a couple of comments.

I'd like an extra small clock option, even the small is a bit obtrusive.

You should probably put the undecorated source files into the download zip, they're all SVN files at the moment.
GeneralNice work!
Member 3292257
10:58 20 Jan '08  
Nice work! Thanks a lot!
Looking forward to your new programms.

Smile Xiaoming Huang


Last Updated 20 Jan 2008 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010