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

  • Anthony Christie, the Chief Marketing Officer for Level Communications, is responsible for customer experience, worldwide marketing and product management. In this informative asset, he shares his insights into why a private network connection to cloud-bases applications is the right decision for your enterprise. Download now to find out more.

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

Most Popular Programming Stories

More for Developers

RSS Feeds

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