Digital Display Classes

Ever wanted a 14 segment display in your app? But you don't like the large amount of bitmaps for every char? And you don't want more bitmaps for another color? Or much more bitmaps for other sizes?

The solution is here!

I present you two new classes

  • CDigiDisplay is a class derived from MFC CStatic class
  • CDigiClock is a class derived from CDigiDisplay class

The Basic idea is from Jvrg Kvnig of the completely free tetris clone "CGTetris". Clock stuff is from Xie Jingwei.


  • Change colors for background, oncolor and offcolor.
  • Special DDX_DigiDisplay functions with format strings.
  • Automatic resizing to client control.
  • One high resolution bitmap for smooth edges.
  • Support for special characters like: ':.*+-'

Change Colors:

There are two functions for changing color:

  • void SetColor(COLORREF OffColor, COLORREF OnColor);
  • void SetBackColor(COLORREF BackColor);

Special DDX_DigiDisplay function with format strings.

  • void DDX_DigiDisplay(CDataExchange* pDX, int nIDC, LPCTSTR lpszFormat, ... );

This is how to use it for above sample.

void CDigitalcounterDlg::DoDataExchange(CDataExchange* pDX)
 DDX_Control(pDX, IDC_QUOTE_STATIC, m_QuoteText);
 DDX_Control(pDX, IDC_COUNT4, m_Count4);
 DDX_Control(pDX, IDC_COUNT3, m_Count3);
 DDX_Control(pDX, IDC_COUNT2, m_Count2);
 DDX_Control(pDX, IDC_COUNT1, m_Count1);
 DDX_Control(pDX, IDC_TIME_STATIC, m_TimeStatic);
 DDX_Text(pDX, IDC_EDIT1, m_dVal);
 DDX_DigiDisplay(pDX, IDC_COUNT1, "A:%6.2lf", m_dNew);
 DDX_DigiDisplay(pDX, IDC_COUNT2, "B:%6.2lf", m_dNew);
 DDX_DigiDisplay(pDX, IDC_COUNT3, "C:%6.2lf", m_dNew);
 DDX_DigiDisplay(pDX, IDC_COUNT4, "D:%6.2lf", m_dNew);
 DDX_DigiDisplay(pDX, IDC_QUOTE_STATIC, m_csQuote);

CDigiDisplay is fully resizable!

To show this in the example I use some classes from Hans B| show the resizing capabilities. You can find him at the 'advanced UI' section with the article 'Dynamic child window repositioning'

How to add a digital character string in your dialog

Steps to follow:

  • Add digidisplay.cpp, digidisplay.h and rgbcolor.h to your project.
    Open digitalcounter.rc and copy the bitmap(s) to your resources
  • Go to your dialog resource and add a static text with the style 'sunken' and type an unique ID
  • Rightclick dialog and choose classwizard
  • Add member variable to your ID and choose category 'control'
  • Go to your dialog header file and include "digidisplay.h".
    Replace CStatic with CDigiDisplay or CDigiClock
  • Use DDX_Digidisplay in DoDataExchange for formatted text or use CDigiDisplay::SetText(...) in OnInitDialog().

Environment for CDigiDisplay

Tested with: Visual C++ 5.0 Windows 9x and NT4.0, Compiled with Warning level 4 and UNICODE.

Have fun!!


  • C. Shawn Bowlin - For suggestions on using CDigidisplay in a MFC extension DLL.

New to release 2

  • C. Shawn Bowlin - CDigidisplay works now in a MFC extension DLL.
  • Various optimizations and solved color switching problem.


Download demo project - 45 Kb
Download source - 10 Kb


  • Won't work with MFC statically linked...

    Posted by Legacy on 01/06/2000 12:00am

    Originally posted by: Lee Emmert


    I kept trying to get this class to work, but each time the control would be empty. I changed the settings of the project to build with shared MFC, and it worked. Can you add support for statically linked MFC?

    Lee Emmert

  • Scrolling Display

    Posted by Legacy on 05/18/1999 12:00am

    Originally posted by: Mark Greenwood

    Liked this very much, I added a scrolling display which you might like to look at

    class CDigiScroll: public CDigiDisplay
    void DoScroll();

    void ScrollText(LPCSTR lpszFormat);
    void SetTextLength(int iMaxLength);
    void SetSpeed(long lSpeed);

    // Overrides
    // ClassWizard generated virtual function overrides
    virtual void PreSubclassWindow();

    // Generated message map functions
    afx_msg void OnTimer(UINT nIDEvent);

    CString m_strTextToScroll;
    long m_lSpeed;
    int m_iTextLength;


    m_iTextLength = 12;
    m_lSpeed = 200l;
    m_strTextToScroll = "This is an example scrolling display ";

    BEGIN_MESSAGE_MAP(CDigiScroll, CDigiDisplay)

    Call Like This

    CDigiScroll m_cdsScrollingText;
    m_cdsScrollingText.ScrollText("This is some text");


    Keep up the good work
    // CDigiClock message handlers

    void CDigiScroll::PreSubclassWindow()
    // TODO: Add your specialized code here and/or call the base class
    // Note: Set the Timer here Pls.
    // Dont set timer in OnCreate(), you cant recieve WM_CREATE
    // when control construted in Dialog template. Say: OnCreate not called.


    void CDigiScroll::ScrollText(LPCSTR lpszFormat)
    m_strTextToScroll = lpszFormat;

    void CDigiScroll::SetSpeed(long lSpeed)
    m_lSpeed = lSpeed;

    void CDigiScroll::SetTextLength(int iMaxLength)
    m_iTextLength = iMaxLength;

    void CDigiScroll::OnTimer(UINT nIDEvent)
    // Take the string, only display the bit of the string that we can see
    CString strTemp;
    CString strNewString;
    CString strScrollString;
    int iLengthOfString = m_strTextToScroll.GetLength();

    strTemp = m_strTextToScroll[0];
    strNewString = m_strTextToScroll.Mid(1);
    strNewString += strTemp;

    strScrollString = strNewString.Mid(0,m_iTextLength);

    m_strTextToScroll = strNewString;


    void CDigiScroll::DoScroll()
    SetTimer(1, m_lSpeed, NULL);

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

Top White Papers and Webcasts

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • In support of their business continuity and disaster recovery plans, many midsized companies endeavor to avoid putting all their eggs in one basket. Understanding the critical role of last-mile connectivity and always available Internet access for their enterprises, savvy firms utilize redundant connections from multiple service providers. Despite the good intentions, their Internet connectivity risk may still be in a single basket. That is because internet service providers (ISPs) and competitive local …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds