65.9K
CodeProject is changing. Read more.
Home

Wall Clock Control

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (12 votes)

Feb 13, 2004

2 min read

viewsIcon

100653

downloadIcon

4544

This article explains how to add a wall clock control to a dialog-based application.

Sample Image - wallclockctrl.jpg

Introduction

This article explains how to add a wall clock control to your dialog-based application. This wall clock control is derived from CStatic. You can customize the clock as per your requirements, viz, change clock hand color, clock dial color, tick color or text color. You can even change your system date/time settings using this control. All you have to do is to change the date/time settings of the clock and system date/time settings will change automatically.

Using the code

Steps for adding the wall clock control to your application:

  1. Copy files WallClockST.h and WallClockST.cpp to your project directory and add them to your project.
  2. Place a Static Control to your dialog from the Control ToolBox.
  3. Using ClassWizard, add a member variable m_Clock for the Static Control, to your dialog class. Make sure that it is a control variable.

  4. Now, in your dialog class header file, add this line on top of your class definition:
    #include "WallClockST.h"
  5. Replace the following line in your dialog class header file:
    CStatic m_Clock;

    with this piece of code:

    CWallClockST m_Clock;

That's it!, Your Wall Clock application is ready. Just execute your program to see the clock running.

Member Functions

Following are the member functions which can be used to change the clock settings:

 void LoadColorSettings();
 // Load the color settings of the clock from your PC.

void SaveColorSettings();
// Save the color settings to your PC.
// The clock settings will be saved as a .sys file in your system directory.

void StopClock();
// Stops the clock.

void StartClock();
// Restarts the clock.

void ResetDate();
// Reset the default date/time settings

void SetDateTime(COleDateTime dt);
// Sets new date/time settings for the clock

void SetTextColor(COLORREF color);
// Sets the text color of the clock

COLORREF GetTextColor();
// Retreives the current text color of the clock

COLORREF GetTickColor();
// Retreives the current tick color of the clock

void SetTickColor(COLORREF color);
// Sets the tick color of the clock
    
void SetDialColor(COLORREF color);
// Sets the dial color of the clock

COLORREF GetDialColor();
// Retreives the current dial color of the clock

COLORREF GetHandColor();
// Retreives the current hand color of the clock

void SetHandColor(COLORREF color);
// Sets the hand color of the clock

Comments

I got the inspiration to develop this control after reading the article by A.Riazi on Analog Clock. I have drawn a circular dial and provided tick marks for the clock, so as to give it the look and feel of a wall clock. Riazi's clock does not provide the facility to change the dial color, tick color and text color of the clock. Also, this control has an advantage in that it displays the current date, which is not present in Riazi's clock.