Static LED control


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

Sample Image


This article presents a CStatic derived class for displaying numbers or text like a LED Display. This control does not use bitmaps. Everything is drawn with lines and Bezier curves. First I made some classes to draw a character, which consists of segments that can be any closed shape, by only giving some points. The points can be connected by lines or by Bezier curves to make nice smoothened characters. The theory of fitting Bezier curves can be found in bezdist.pdf, created by Jim Fitzsimmons, in my demo project cabinet. The CDigistring resizes itself automatically, which can be experienced with the demo app, wherefore I used the resizing dialog code from Hans Bühler.

To to design the characters I looked around for different styles. The most inspiration came out of my car. I used characters from the date/time/temperature display and from my RDS-radio. 14- And 7-segment displays in straight and smooth style are supported and one common character for displaying a decimal point or a colon. I changed the designs a lot to get aesthetically best results, but I didn't went crazy by changing all the points every time because I do some nifty mirrorring for most of the segments. For example i only specified 5 segments for the 14 segment display.

The Designs

You can modify these if you like, then you can take them over to the source the same way as I did. The height of every design is the same only the width may be different, necessary for easy scaling.

Changing styles

 BOOL ModifyDigiStyle(DWORD dwRemove, DWORD dwAdd);

With the MidifyDigiStyle function you can add or remove specific CDigistring styles. The styles, which can be combined by using the bitwise OR (|) operator, are:

CDigistring::DS_SMOOTH   // Smooth kind of characters
CDigistring::DS_STYLE14  // use always 14 segment display.
CDigistring::DS_SZ_PROP  // size proportional(default)

How to use (in a dialog):

  1. Add digistring.h, digistring.cpp, memdc.h, curvefit.h, curvefit.cpp and rgbcolor.h to your project environment.
  2. Add a static control to your dialog resource.
  3. Change its ID to something like IDC_LEDTEXT, open classwizard and assign a member variable, type control (CStatic) to it (m_LedText for example).
  4. Open your dialog class' header file.
    Add #include "digistring.h".
    Find the line CStatic m_LedText and replace the CStatic by CDigistring.
  5. In OnInitDialog() you can give it some text with SetText(),
    change the colors with SetColor() or for the background SetBackColor() or you can
    set the right style with ModifyDigistyle().
  6. Compile and run.


  • Hans Bühler - For using his resizing software for the demo application;
  • Keith Rule - For creating the memdc class for flickerfree drawing.


Download demo project - 163 Kb
Download source - 13 Kb


  • Thank you!

    Posted by Legacy on 01/06/2004 08:00am

    Originally posted by: zhaozhifang

    It is the great work what I am looking for. And also the reference of resize dialog. Thanks a lot.


  • Gread work indeed.

    Posted by Legacy on 03/24/2003 08:00am

    Originally posted by: Claude Mally

    I tought I would see yet another 7 segment static control, but it contains lots of other goodies!
    Great code, lots of attention to details!

  • Cool class... any ideas on how to make it faster?

    Posted by Legacy on 03/20/2001 08:00am

    Originally posted by: Dave Parks

    This is a really cool class for starters. Congrats!

    I was trying to use this class to make a real-time clock control and I'm having problems because my clock control needs to update on close to a millisecond basis. The issue I'm having is that every time you change the text in the control it invalidates the entire control window and redraws it. If you do this often in a relatively short period of time, it spikes the processor (or two) all over the place.

    Not really a problem with your code but do you have any ideas on how to optimize the drawing routines to speed it up?


  • Extremely cool.

    Posted by Legacy on 01/07/2001 08:00am

    Originally posted by: Dave Steckler

    Wow. Nifty. Exactly what I was hoping I wasn't going to have to write myself. I love the (auto) resizing capability.

    My only complaint isn't with your stuff, it's with the STL. When compiling under VC6, there are some warnings in the STL that I simply can't turn off. It gets hard to see any errors of my own in there.

    You could solve this by making a single include file which just defined the basics for apps which use your class, and have the STL-based stuff in another include file (which I wouldn't have to compile when I compile my stuff).

    But on the whole, this is way cool. Good job.

    Thanks for writing this wonderful control!

    Dave Steckler

  • Very Well Done!

    Posted by Legacy on 08/11/2000 07:00am

    Originally posted by: Erik O'Neill

    I just wanted to say thank you for writing and sharing this wonderful class! I am writing a program to interface with Winamp (not a plugin) and will have a server/client, this helps make it look much better, for things like the play time. Again, thanks a lot and keep up the good work!

    -Erik O'Neill

  • Nice

    Posted by Legacy on 03/01/2000 08:00am

    Originally posted by: Charles

    Very nice. Not sure what i'll use it for, but nice :-)

  • Great class - just some minor suggestions

    Posted by Legacy on 02/18/2000 08:00am

    Originally posted by: Adrian Stanley

    First off, this class is really cool.

    I hope you don't mind me making some small suggestions to make it even better. These are all really to do with the public interface code style.

    1. Your main header should only have in it the declarations which users of the class need to know about, e.g., CDigistring class. I'd move all other classes out, probably to the cpp.

    2. Why CDigistring? This is not a string class, but a static control. CDigiStatic or CLEDStatic would be much more accurate.

    3. I suggest some of the CDigistring methods are redefined to reflect MFC standards:

    SetText -> SetWindowText i.e., override CWnd::SetWindowText().

    ModifyDigiStyle -> BOOL ModifyStyle( DWORD dwRemove, DWORD dwAdd, UINT nFlags = 0 ), i.e., override CWnd::ModifyStyle.

    SetColor -> virtual COLORREF SetTextColor(COLORREF), i.e., modelled on CDC.

    SetBackColor -> virtual COLORREF SetBkColor(COLORREF), i.e., modelled on CDC.

  • 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