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.

Features:

  • 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)
{
 cdxCSizingDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CDigitalcounterDlg)
 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);
 //}}AFX_DATA_MAP
 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!!

Acknowledgements

  • 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.

Downloads

Download demo project - 45 Kb
Download source - 10 Kb


Comments

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

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

    Originally posted by: Lee Emmert

    Hello,

    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?

    Thanks,
    Lee Emmert
    lemworld@lemworld.com

    Reply
  • 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
    {
    public:
    void DoScroll();
    CDigiScroll();

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

    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CDigiScroll)
    protected:
    virtual void PreSubclassWindow();
    //}}AFX_VIRTUAL

    // Generated message map functions
    protected:
    //{{AFX_MSG(CDigiScroll)
    afx_msg void OnTimer(UINT nIDEvent);
    //}}AFX_MSG

    private:
    CString m_strTextToScroll;
    long m_lSpeed;
    int m_iTextLength;

    DECLARE_MESSAGE_MAP()
    };

    CDigiScroll::CDigiScroll()
    {
    m_iTextLength = 12;
    m_lSpeed = 200l;
    m_strTextToScroll = "This is an example scrolling display ";
    }

    BEGIN_MESSAGE_MAP(CDigiScroll, CDigiDisplay)
    //{{AFX_MSG_MAP(CDigiScroll)
    ON_WM_TIMER()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()


    Call Like This

    CDigiScroll m_cdsScrollingText;
    m_cdsScrollingText.ScrollText("This is some text");
    m_cdsScrollingText.SetSpeed(500);
    m_cdsScrollingText.SetTextLength(15);
    m_cdsScrollingText.DoScroll();


    //

    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.
    //

    CDigiDisplay::PreSubclassWindow();
    }

    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;

    SetText(strScrollString.GetBuffer(0));
    }

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

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

Top White Papers and Webcasts

  • On-demand Event Event Date: August 27, 2015 With the cloud enabling companies to spin up servers and stand up data stores more quickly, mobile apps can be created faster, reducing the time-to-value. But three major obstacles stand in the way for many organizations: The backlog of app project requests confronting every enterprise regardless of their internal app development capabilities Finding and employing better, faster tools to speed and simplify the process of developing those apps. The emergence of …

  • U.S. companies are desperately trying to recruit and hire skilled software engineers and developers, but there is simply not enough quality talent to go around. Tiempo Development is a nearshore software development company. Our headquarters are in AZ, but we are a pioneer and leader in outsourcing to Mexico, based on our three software development centers there. We have a proven process and we are experts at providing our customers with powerful solutions. We transform ideas into reality.

Most Popular Programming Stories

More for Developers

RSS Feeds

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