带透明背景的大时钟
带透明背景的大时钟,基于 7 段 LCD。
引言
这是一个基于7段式LCD的透明桌面时钟。我之前发表过一篇关于7段式LCD的文章,并基于该控件,快速地制作了这个透明桌面时钟。我很乐意与Code Project社区分享它。
背景
我的一个同事路过时对BigClock印象深刻。他立即要求给我一份拷贝,并且我一直能在他的屏幕上看到它。
 
 
Using the Code
7段式代码在透明环境下无需修改即可工作。但是,我添加了一个类拦截片段,以在运行时擦除CStatic框架。这样,对话框编辑器中的控件可以具有“凹陷”样式,以便查看控件的大小和位置。这使得设计控件的表单更容易。这是执行此操作的代码:
// 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);
    }
有人会问为什么要在OnPaint中执行此操作?嗯,基于CStatic 和 CWnd 的控件不会接收很多消息。这样,我们就可以利用即使是static 控件也无法避免的唯一消息:绘制。
特点
我添加了12/24小时切换、秒显示开关以及小/中/大尺寸控制。我还添加了自动启动、置顶和窗口位置持久化功能。
屏幕截图
银色主题上的中等尺寸设置
 
 
小尺寸设置非常适合始终显示在屏幕上的时钟。
 
 
这是BigClock 在我的开发机器上的显示效果,位于右上角。
 
 
BigClock 在大尺寸设置下以及设置/配置对话框
 
 
关注点
创建透明对话框的代码片段如下:
// 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 
历史
- 2008年1月20日:初始版本,添加了任务栏隐藏功能




