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:
- Replace the following line in your dialog class header file:
with this piece of code:
That's it!, Your Wall Clock application is ready. Just execute your program to see the clock running.
Following are the member functions which can be used to change the clock settings:
void SetDateTime(COleDateTime dt);
void SetTextColor(COLORREF color);
void SetTickColor(COLORREF color);
void SetDialColor(COLORREF color);
void SetHandColor(COLORREF color);
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.