Click here to Skip to main content
15,886,873 members
Articles / Desktop Programming / MFC

Wall Clock Control

Rate me:
Please Sign up or sign in to vote.
4.00/5 (14 votes)
12 Feb 20042 min read 99.5K   4.5K   43  
This article explains how to add a wall clock control to a dialog-based application.
#ifndef _WALLCLOCKST_H_
#define _WALLCLOCKST_H_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// WallClockST.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CWallClockST window

class CWallClockST : public CStatic
{
// Construction
public:
	CWallClockST();

// Attributes
public:
	CString sDate;
// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CWallClockST)
	//}}AFX_VIRTUAL

// Implementation
public:
	void LoadColorSettings(); // Load the color settings of the clock from your PC.
	void SaveColorSettings(); // Save the color settings to your PC.
	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
	virtual ~CWallClockST();

protected:
 	void DrawDate(CDC *pDC,CString str,int x,int y,COLORREF color);
    void DrawClockFace (CDC* pDC);
    void DrawSecondHand (CDC* pDC, int nLength, int nScale, int nDegrees,
        COLORREF clrColor);
    void DrawHand (CDC* pDC, int nLength, int nScale, int nDegrees,
        COLORREF clrColor);

	CRgn m_rgn;

	COleDateTime time;

	int m_nPrevSecond;        
    int m_nPrevMinute;
    int m_nPrevHour;
	int m_nSecond;        
    int m_nMinute;
    int m_nHour;
	COleDateTime m_PrevDate;

	// Generated message map functions
protected:
	COLORREF m_nColor;
	COLORREF m_bkClr;
	COLORREF m_dialClr;
	COLORREF m_tickClr;
	COLORREF m_textClr;
	//{{AFX_MSG(CWallClockST)
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnPaint();
	afx_msg void OnClose();
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // _WALLCLOCKST_H_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
India India
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.

Comments and Discussions