dcsimg

Digital Display Classes

WEBINAR:
On-Demand

Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame


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


Most Popular Programming Stories

More for Developers

RSS Feeds

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