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:


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

Top White Papers and Webcasts

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

  • The impact of a data loss event can be significant. Real-time data is essential to remaining competitive. Many companies can no longer afford to rely on a truck arriving each day to take backup tapes offsite. For most companies, a cloud backup and recovery solution will eliminate, or significantly reduce, IT resources related to the mundane task of backup and allow your resources to be redeployed to more strategic projects. The cloud - can now be comfortable for you – with 100% recovery from anywhere all …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds