Static LED control

Sample Image

Overview

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.

Acknowledgements

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

Downloads

Download demo project - 163 Kb
Download source - 13 Kb


Comments

  • Thank you!

    Posted by Legacy on 01/06/2004 12: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.

    Zhifang

    Reply
  • Gread work indeed.

    Posted by Legacy on 03/24/2003 12: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!

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

    Posted by Legacy on 03/20/2001 12: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?

    Thanks
    -Dave

    Reply
  • Extremely cool.

    Posted by Legacy on 01/07/2001 12: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

    Reply
  • Very Well Done!

    Posted by Legacy on 08/11/2000 12: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

    Reply
  • Nice

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

    Originally posted by: Charles

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

    Reply
  • Great class - just some minor suggestions

    Posted by Legacy on 02/18/2000 12: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.

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

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: October 23, 2014 @ 12:00 p.m. ET / 9:00 a.m. PT Despite the current "virtualize everything" mentality, there are advantages to utilizing physical hardware for certain tasks. This is especially true for backups. In many cases, it is clearly in an organization's best interest to make use of physical, purpose-built backup appliances rather than relying on virtual backup software (VBA - Virtual Backup Appliances). Join us for this eSeminar to learn why physical appliances are preferable to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds