The CStaticCounter class simplifies the display of time and numerical
values using a digital-style counter - without using bitmaps.

The class uses Keith Rule's double-buffering
class to completely remove flicker, and it uses MoveTo/LineTo for
drawing, and therefore has no dependancies on bitmaps.

The original class was written quite a while ago now and can be found at CodeGuru. This
version, however, has a lot more functionality. New features include:

Floating Point display

Time Display

Bug fixed: Memory leak in Draw() function

Mouse interaction (optional) with the ability to make large & small changes, and
these changes adapt to whether the control is in 'float' or 'integer' mode.

3D Progress bar class (I 'borrowed' the technique from the very cool <a
href="http://www.codeguru.com/controls/MacProgress.shtml">progress control by Paul
Meidinger) which I implemented as a separate class for max re-use

Built-in (optional) notification. Trap WM_UPDATE_STATIC messages in your dialog and get
up-to-date change notifications when user interacts with the control.

Supply ID's to each or any of your CStaticCounter controls to enable you to
identify them upon trapping the WM_UPDATE_STATIC message

Set (optional) blank padding for either float or integer displays

Define your own format strings to further customise the output display of the CStaticCounter

The class also uses static control's dimensions to calculate metrics, which means it'll
draw well formed digits with minimal intervention, regardless of the control's size.

How to use the CStaticCounter

If the control is being used to display integer values:

Single Click Left Mouse Button:

Decreases the value by 1

Single Click Right Mouse Button:

Increases the value by 1

Left Mouse Button and drag:

Increases or decreases by (mouse distance*1)

Right Mouse Button and drag:

Increases or decreases (mouse distance*0.01) - but
displays a whole number

This function enables you to simply tell the control to display, for instance, 5196
seconds by simply typing Display(5196). The output will be displayed in
D:H:M:S format unless you change the format string (last parameter) accordingly.

void DisplayCurrentTime(CString strFormat = "%H:%M:%S")

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.

Comments and Discussions

besides the fact that it's a very useful control, I was wondering why a MemDC was used? I could see the difference (flickers) when I'm changing the code and running it without the MemDC, but technically - how does it work and why is it needed?