Click here to Skip to main content
14,031,266 members
Click here to Skip to main content
Add your own
alternative version


184 bookmarked
Posted 9 Feb 2000
Licenced CPOL

Static LED control - CDigiStatic 1.3

, 5 Oct 2002
Rate this:
Please Sign up or sign in to vote.
A control to display text or numbers with a 14 or 7 segment display.
  • Download demo project - 372 Kb
  • Download source files - 14 Kb
  • Sample Image - DigiStatic.gif


    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 CDigiStatic resizes itself automatically, which can be experienced with the demo app, wherefore I used the resizing dialog code from Hans Bühler.

    To design the characters I looked around for different styles. The best 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 go crazy by changing all the points every time because I do some nifty mirroring for most of the segments. For example I only specified 5 segments for the 14 segment display.

    The demo application shows all possibilities of this control.

    Overview of possible Characters

    7-segment straight 7-segment smooth 14-segment straight 14-segment smootht Colon and decimal point

    These are normalized characters with all segments turned on in all styles. The coordinates of these pictures were used to find the corners and Bezier points. You can adjust the coordinates or dimensions 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.

    Public Functions


    void SetText(LPCTSTR lpszText);

    Call this function to set the text of the control. For more info see SetDrawImmediately()


    void Format(LPCTSTR lpszFormat, ...);<br>
    void Format( UINT nFormatID, ... );

    Call this member function to write formatted data to a CDigiStatic in the same way that sprintf formats data into a C-style character array. This function formats and stores a series of characters and values in the CDigiStatic. Each optional argument (if any) is converted and output according to the corresponding format specification in lpszFormat or from the string resource identified by nFormatID.


    void SetColor(COLORREF OffColor, COLORREF OnColor);

    Sets the on and off color of the segments of the CDigiStatic control. Segments that are off will not be painted when the DS_NO_OFF style is used.


    COLORREF GetOnColor() const

    Call this member function to retrieve the color that is used to indicate the segment is on


    COLORREF GetOffColor() const

    Call this member function to retrieve the color that is used to indicate the segment is off


    void SetDrawImmediately(BOOL Enable = TRUE);

    If Enable set to TRUE a call to SetText() or Format() will redraw the window before the function returns. If Enable set to FALSE (the default of CDigiStatic) the client area is marked for painting when the next WM_PAINT message occurs.


    COLORREF SetBkColor(COLORREF BackColor = BLACK);

    Sets the current background color to the specified color and returns the previous background color. The value of the background color will be ignored when Transparency mode is enabled.


    void SetTransparent(BOOL bSet = TRUE);

    Set to TRUE only the segments will be drawn and the background will be transparent and show the window underneath it. Nice if you use a skinned window. Set to FALSE will fill the background with the current background color.


    BOOL ModifyDigiStyle(DWORD dwRemove, DWORD dwAdd);

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

    • CDigiStatic::DS_SMOOTH // Smooth kind of characters
    • CDigiStatic::DS_STYLE14 // use always 14 segment display.
    • CDigiStatic::DS_SZ_PROP // size proportional(default)
    • CDigiStatic::DS_NO_OFF // Don't draw the off segments
    • CDigiStatic::DS_SOFT // ambient bleeding to background

    How to use (in a dialog):

    1. Add digistatic.h, digistatic.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 class-wizard and assign a member variable, type control (CStatic) to it (m_LedText for example).
    4. Open your dialog class's header file. Add #include "digistatic.h". Find the line CStatic m_LedText and replace the CStatic by CDigiStatic.
    5. In OnInitDialog() you can give it some text with SetText(), change the colors with SetColor() or for the background SetBkColor(). 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. Modified for support of transparent background
    • Massimo Colurcio - HMX controls for making a skinned demo application easy.
    • Daniel DeGeest - For helping me with transparency, testing and suggestions.


    1.0 February 2000First release version. Finally I could say goodbye to my old class with bitmaps and enjoy the new quality. This nice control just had to be shared
    1.1 April 2001Use Caption as default text. Changed from STL to Afx templates. After a suggestion I changed SetBackColor to SetBkColor. I apologize for keeping this baby for myself because I wanted to add and change more
    1.2 May 2002Added option to draw immediately. Changed CDigiString to CDigiStatic because it is a derived from a Static control. After giving no problems for long time it was ready to be released again
    1.3 October 2002Added transparency option with help of Daniel. Introduction of 5 new characters /\[]' (suggested by daniel for using in his great Winamp plugin). Added new DS_NO_OFF and DS_SOFT styles to respectively not to show segments that are "off" and to remove the soft edge of a segment. Improved demo app with skin was created to show all the options. This will be the third release and I call it the "feature update"


    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


    About the Author

    Michel Wassink
    Netherlands Netherlands
    Michel is from the Netherlands. I make software for my job and like to do racing games in free time.

    And a good mind has to be in a healthy body. That is why I do some fitness and do not eat to much pizza.

    You may also be interested in...

    Comments and Discussions

    GeneralMy vote of 5 Pin
    Member 1006875925-May-13 15:14
    memberMember 1006875925-May-13 15:14 
    GeneralGreat Control !! Pin
    wz123wu24-May-10 21:54
    memberwz123wu24-May-10 21:54 
    GeneralRe: Great Control !! Pin
    Michel Wassink22-Jun-10 2:48
    memberMichel Wassink22-Jun-10 2:48 
    GeneralGreat but out of date Pin
    tlhIn`toq15-Sep-09 8:37
    membertlhIn`toq15-Sep-09 8:37 
    GeneralRe: Great but out of date Pin
    Apuhjee22-Oct-09 7:17
    memberApuhjee22-Oct-09 7:17 
    GeneralMemory leak Pin
    Max23511-Mar-06 0:00
    memberMax23511-Mar-06 0:00 
    GeneralRe: Memory leak Pin
    Michel Wassink1-Mar-06 2:40
    memberMichel Wassink1-Mar-06 2:40 
    QuestionRe: Memory leak Pin
    Willi_837-Jul-09 12:01
    memberWilli_837-Jul-09 12:01 

    I have also a problem with a memory leak using this control.

    It seems that the memory is lost every time the control is redrawn.

    When you move the window of my application some memory is lost. Also if you change the text of the control!

    I have the same problem with the CLcd7 Class.

    Can anyone help me please? Confused | :confused:

    AnswerRe: Memory leak Pin
    Michel Wassink9-Jul-09 10:26
    memberMichel Wassink9-Jul-09 10:26 
    GeneralRe: Memory leak Pin
    Willi_8326-Jul-09 9:23
    memberWilli_8326-Jul-09 9:23 
    GeneralModify for displaying comma Pin
    Samuele31-Jan-06 23:00
    memberSamuele31-Jan-06 23:00 
    GeneralUsing in a CFormView Pin
    sbt18-Oct-05 7:40
    membersbt18-Oct-05 7:40 
    GeneralSolution- for anyone else trying to do this Pin
    sbt18-Oct-05 12:51
    membersbt18-Oct-05 12:51 
    GeneralCompiling errors Pin
    kezhu1-Sep-05 17:33
    memberkezhu1-Sep-05 17:33 
    GeneralRe: Compiling errors Pin
    Rick York1-Sep-05 18:54
    mveRick York1-Sep-05 18:54 
    GeneralRe: Compiling errors Pin
    Michel Wassink1-Sep-05 19:54
    memberMichel Wassink1-Sep-05 19:54 
    GeneralFANTASTIC code !!! Pin
    KurtCocain17-Aug-04 9:47
    memberKurtCocain17-Aug-04 9:47 
    GeneralRe: FANTASTIC code !!! Pin
    Michel Wassink5-Oct-04 19:45
    memberMichel Wassink5-Oct-04 19:45 
    GeneralCompilation Errors Pin
    rmnowick9-Mar-04 15:22
    memberrmnowick9-Mar-04 15:22 
    GeneralRe: Compilation Errors Pin
    rmnowick9-Mar-04 15:37
    memberrmnowick9-Mar-04 15:37 
    GeneralRe: Compilation Errors Pin
    Michel Wassink9-Mar-04 19:45
    memberMichel Wassink9-Mar-04 19:45 
    GeneralRe: Compilation Errors Pin
    rmnowick10-Mar-04 5:33
    memberrmnowick10-Mar-04 5:33 
    GeneralRe: Compilation Errors Pin
    rmnowick10-Mar-04 13:47
    memberrmnowick10-Mar-04 13:47 
    GeneralRe: Compilation Errors Pin
    ananth_rs5-May-06 21:36
    memberananth_rs5-May-06 21:36 
    QuestionWTL Version? Pin
    mjsiers19-Nov-03 11:06
    membermjsiers19-Nov-03 11:06 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
    Web01 | 2.8.190419.4 | Last Updated 6 Oct 2002
    Article Copyright 2000 by Michel Wassink
    Everything else Copyright © CodeProject, 1999-2019
    Layout: fixed | fluid