Click here to Skip to main content
12,997,158 members (68,153 online)
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 12 Dec 2002

MFC ActiveX Digital Clock

, 12 Dec 2002
Rate this:
Please Sign up or sign in to vote.
A digital clock ActiveX control.

Sample Image - clock.gif


The main idea of this project is creation of a digital segment indicator. In the first version I had developed one segment indicator. After this I grouped some segment indicators and colon indicator and made the DigitalClock class. The next step was creation of an Active X control, based on DigitalClock class.

The base class is CDigit. This class draws segments of a digit with given brush, pen and width. The common function of this class is drawDigit(HDC dc, const int iDigit). This function gives the device context for painting and the number.

// draw digit, form 0 - 9

void CDigit::drawDigit( HDC dc, const int iDigit ) 
switch( iDigit )
case 0:

drawSegment(dc, UET, true ); 
drawSegment( dc, RUET, true ); 
drawSegment( dc, RDET, true ); 
drawSegment( dc, DET, true ); 
drawSegment( dc, LDET, true ); 
drawSegment( dc, LUET, true );
drawSegment( dc, MET, false );

case 1:

drawSegment( dc, UET, false ); drawSegment( dc, RUET, true ); 
drawSegment( dc, RDET, true ); drawSegment( dc, DET, false ); 
drawSegment( dc, LDET, false ); drawSegment( dc, LUET, false );
drawSegment( dc, MET, false );

.........In same manner draw segments for other digits...............

The digit enumeration:

enum DEType

UET = 0,
RUET = 1,
RDET = 2,
DET = 3,
LDET = 4,
LUET = 5,
MET = 6


The function drawSegment is used for painting of one segment:

// draw segment with selected color and pen
void CDigit::drawSegment( HDC dc, const DEType segType, 
                                const bool bState ) const 

HBRUSH oldBrush = (HBRUSH) SelectObject( dc, 
         (bState) ? m_activeBrush : m_inactiveBrush );
HPEN oldPen = (HPEN) SelectObject( dc, (bState) ? m_hActPen : m_hInactPen );
Polygon( dc, m_ptDG[ segType ], 6 );
SelectObject( dc, oldPen );
SelectObject( dc, oldBrush );


drawSegment selects the correspond brush and pen and calls Poligon API function, which draws a segment.

In this project, I had some difficulties with persisting of control's properties. After some experiments I did following:

void CDigitalClockCtrl::DoPropExchange(CPropExchange* pPX)
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));

// TODO: Call PX_ functions for each persistent custom property.
long lSOffset = GetLSOffset();
long lSWidth = GetLSWidth();
long lXOffset = GetLXOffset();
long lYOffset = GetLYOffset();
OLE_COLOR clrActive = GetClrActive();
OLE_COLOR clrBkgnd = GetClrBkgnd(); 
OLE_COLOR clrInactive = GetClrInactive();

PX_Long( pPX, _T("lSOffset"), lSOffset );
PX_Long( pPX, _T("lSWidth"), lSWidth );
PX_Long( pPX, _T("lXOffset"), lXOffset );
PX_Long( pPX, _T("lYOffset"), lYOffset );

PX_Color( pPX, _T("clrActive"), clrActive );
PX_Color( pPX, _T("clrBkgnd"), clrBkgnd );
PX_Color( pPX, _T("clrInactive"), clrInactive );

SetLSOffset( lSOffset );
SetLSWidth( lSWidth );
SetLXOffset( lXOffset );
SetLYOffset( lYOffset );
SetClrActive( clrActive );
SetClrBkgnd( clrBkgnd ); 
SetClrInactive( clrInactive );


First I get control's properties by invoking control's Getxxx functions, after that call macros and call Setxxx functions to set new properties' values.

Using the component

  1. Register component by using: regsvr32 <path\to installed\axtivex>
  2. Add component to projects
  3. The component icon will appear on controls toolbar
  4. Using drag-and-drop operation, put the component into dialogs.
  5. Set appropriate settings


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


About the Author

Nikolai Serdiuk
Web Developer
Bulgaria Bulgaria
I am a senior developer in <a href=>Melon Technologies Ltd.

You may also be interested in...

Comments and Discussions

GeneralOleControl from dialog Pin
ant_kampo8-Aug-07 1:24
memberant_kampo8-Aug-07 1:24 
GeneralDoPropExchange Pin
Zainu13-Jun-07 4:08
memberZainu13-Jun-07 4:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170622.1 | Last Updated 13 Dec 2002
Article Copyright 2002 by Nikolai Serdiuk
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid