Adding digital counters


CDigitST is a class derived from MFC CStatic class.
This class easly lets put digital counters inside your applications!
CDigitST features:
  • Easy to use!
  • Create a new digital style just drawing a bitmap
  • Automatic resize feature
  • Written in Visual C++ v5.0
  • Full source code included!
  • It's free!

You are encouraged to use this class everywhere you want; there is no fee required for CDigitST. Freely add modifications and/or fix bugs, but please, send any of these to SoftechSoftware!

How to integrate CDigitST in your application

In your project include the following files:
You also need a bitmap containing the actual digits. This bitmap must have the following format:
  • Each digit must have the same width and height
  • In the bitmap must be present 12 digits: 0..9 [blank] and [-]
    [blank] will be used for zeroes to the left
    [-] will be used as minus sign
For example include in your project Small_1.bmp and call it IDB_SMALL1.

With dialog editor create a static control called, for example, IDC_COUNTER and create a member variable for it:

   CDigitST m_dgtCounter;

Now attach the static control to CDigitST. In your OnInitDialog procedure:
   // Call the base method

   // Create the IDC_COUNTER digital counter
   m_dgtCounter.SubclassDlgItem(IDC_COUNTER, this);

The control can display any number of digits you want (maximum is 10). Don't worry about the control dimensions since it will be resized at runtime depending on the precision (number of digits) you want. The control can be expanded/shrinked from left-to-right (or viceversa) and from top-to-bottom (or viceversa). See "CDigitST members" section for a detailed explanation of all possible resize values.

Set resize direction to left-to-right and top-to-bottom:

   // Set resize direction
   m_dgtCounter.SetResize(CDigitST::ST_RIGHT | CDigitST::ST_BOTTOM);
Now assign the bitmap to the control and set its precision:
   // Assign bitmap and precision
   m_dgtCounter.SetStyle(IDB_SMALL1, 5);    // The control will be automatically resized

CDigitST has a default starting value of 0 (zero) but any value (in the range of signed integers) can be assigned to it:

   // Assign a starting value
By default the zeroes at the left of the value will be not displayed. This feature can be enabled/disabled at any time:
   // Enable zero padding
Your static control is now a CDigitST!

Look inside the demo program to learn more about CDigitST. This is the best way! Also give a look to the included bitmaps to learn how to implement your own digital styles!

CDigitST members

BOOL SetStyle(UINT nBitmapId, int nPrecision);
Set digital style and precision (number of digits).
The control will be automatically resized.
Input values:
  • nBitmapId
    The resource bitmap to use as digits
  • nPrecision
    Number of digits to display
Return value:
  • Nonzero if successful; otherwise 0.
m_dgtCounter.SetStyle(IDB_SMALL1, 5);

void SetValue(int nValue, BOOL bRepaint = TRUE);
Set current digital counter value.
Input values:

  • nValue
    The new value
  • bRepaint
    If TRUE the control is immediately redrawn

int GetValue();
Get current digital counter value.
int nCurrent = m_dgtCounter.GetValue();

void SetPrecision(int nPrecision, BOOL bResize = TRUE);
Set number of displayed digits (called precision).
Input values:

  • nPrecision
    Number of digits to display
    If precision is too low the counter will be truncated at the left
    Precision is limited between 1 and 10 (this limit can be easly modified)
  • bRepaint
    If TRUE the control is immediately redrawn

int GetPrecision();
Get number of displayed digits.
int nPrecision = m_dgtCounter.GetPrecision();

void SetResize(DWORD dwResize, BOOL bResize = TRUE);
Set control resize direction.
Input values:

  • dwResize
    Resize direction. This value can be a bitwise-OR operation of the following values:
    • ST_LEFT
      Resize to left
    • ST_RIGHT
      Resize to right
    • ST_TOP
      Resize to top
      Resize to bottom
  • bResize
    If TRUE the control is immediately resized
m_dgtCounter.SetResize(CDigitST::ST_LEFT | CDigitST::ST_TOP);

DWORD GetResize();
Get control resize direction.
DWORD dwDirection = m_dgtCounter.GetResize();

void SetZeroPadding(BOOL bPad = FALSE, BOOL bRepaint = TRUE);
Enable/Disable showing zeroes at the left of the counter (called ZeroPadding).
Input values:

  • bPad
    If TRUE the zeroes at the left are displayed
  • bRepaint
    If TRUE the control is immediately redrawn

BOOL GetZeroPadding();
Get ZeroPadding state.
BOOL bPadding = m_dgtCounter.GetZeroPadding();

void Inc(BOOL bRepaint = TRUE);
Increment current digital counter value.
Input values:

  • bRepaint
    If TRUE the control is immediately redrawn

void Dec(BOOL bRepaint = TRUE);
Decrement current digital counter value.
Input values:

  • bRepaint
    If TRUE the control is immediately redrawn

static const short GetVersionI()
static const char* GetVersionC()

Return CDigitST version.
int nVer = CDigitST::GetVersionI(); // Divide by 10 to get actual version
char szVer[20];
strcpy(szVer, CDigitST::GetVersionC());

Download the demo project (103Kb).


  • CDigitST v1.0
    First release

Things to do

  • Any suggestion?

Contact addresses

SoftechSoftware E-Mail:
SoftechSoftware homepage:
CDigitST homepage:


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • U.S. companies are desperately trying to recruit and hire skilled software engineers and developers, but there's simply not enough quality talent to go around. In response, companies often resort to inferior solutions -- hiring substandard developers and engineers, recruiting talent on a part-time or temporary basis, poaching people from competitors, or burdening an already stressed IT staff for more of their labor. Fortunately, there's a better solution. Read this white paper to learn the business value of …

  • As the mobile enterprise marketplace expands and customer needs grow more diverse, Samsung recognizes that solution partners and developers play an essential role by continually innovating to meet their customers' needs. Samsung works to provide these developers and partners with the latest tools and resources needed to create these solutions. Read this program guide to learn how the Samsung Enterprise Alliance Program provides partners and developers with Samsung enterprise software development kits (SDKs) …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date