Cool Rolling Clock Control | CodeGuru

Cool Rolling Clock Control

Overview This is a Clock control  which is able to roll the digit away as the time elapses, just like what the oil meter does in the old car. This is a control derived from the CStatic, it’s inspired by the code of Mr. Mark Findlay for his "Scrolling credits dialog". However, a lot was […]

Written By
CodeGuru Staff
CodeGuru Staff
Mar 14, 2001
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Overview

This is a Clock control  which is able to roll the digit away as the time elapses,
just like what the oil meter does in the old car.

This is a control derived from the CStatic, it’s inspired by
the code of Mr. Mark Findlay for his "Scrolling credits
dialog
". However,

a
lot was rewritten. I only focus on the rolling part of the code, and didn’t
provide the interface of the color (Bk&Text), although providing 

those
stuff looks like more professional. But that would be easy for you guys 
if you like, as well as the font. 🙂

Using the Rolling Clock Control

  1. Insert the file RollingClk.h
    and RollingClk.cpp into your project
  2. Create a dialog in your project. Drag a static control from the control
    panel; setting it to a reasonable size;
  3. In the dialog’s header file, add the following line
    // I supposed that you add the file to the same path of 
    // the project, or you have to 
    #include "rollingClk.h"
    
    //include the whole path
    ...
    
    CRollingClk m_Static;
    
  4. In the OnInitDialog() of your Dialog class, add the following code
    // the "IDC_STATIC1" is the ID of your static control
    m_Static.SubclassDigItem(IDC_STATIC1,this);
    
    // you can also set the first two parameters as 
    // text & Bk Color,
    m_Static.Start();
    
    // and the third as the slipping speed, or nothing--it 
    // will choose the default values.
    And In the OnPaint() of Parent Dialog, you should add:
    else
    {
    ...
    // add here	
    m_Static.SetFirstTime(TRUE);
    CDialog::OnPaint();
    

So that when the Dialog thrives from minimum, the static will redraw. That’s it!

Downloads

Download source – 4 Kb
Download demo project – 19 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.