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:
- Copy files WallClockST.h and WallClockST.cpp to your project directory and add them to your project.
- Place a Static Control to your dialog from the Control ToolBox.
- Using ClassWizard, add a member variable
m_Clock
for the Static Control, to your dialog class. Make sure that it is a control variable.
- Now, in your dialog class header file, add this line on top of your class definition:
#include "WallClockST.h"
- 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();
void SaveColorSettings();
void StopClock();
void StartClock();
void ResetDate();
void SetDateTime(COleDateTime dt);
void SetTextColor(COLORREF color);
COLORREF GetTextColor();
COLORREF GetTickColor();
void SetTickColor(COLORREF color);
void SetDialColor(COLORREF color);
COLORREF GetDialColor();
COLORREF GetHandColor();
void SetHandColor(COLORREF color);
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.
I am currently working as Senior Software Engineer in a U.S.based Multi National Company. I have worked on projects related to various fields including Process Control, Security Solutions usng Biometrics, Artificial Intelligence etc.
I have developed many programs related to security solutions and embedded systems.