Virtual Developer Workshop: Containerized Development with Docker

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|hler.to 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 08: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 07: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);

  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

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