Click here to Skip to main content
Licence 
First Posted 17 Jan 2000
Views 121,610
Bookmarked 107 times

An LED Style display control and bar control

By | 17 Jan 2000 | Article
A control to display time, floating point numbers or integers using an LED digital-style display
  • Download demo project - 32 Kb
  • Download source files - 8 Kb
  • Sample Image - StaticCounter.gif

    The CStaticCounter class simplifies the display of time and numerical values using a digital-style counter - without using bitmaps.

    The class uses Keith Rule's double-buffering class to completely remove flicker, and it uses MoveTo/LineTo for drawing, and therefore has no dependancies on bitmaps.

    The original class was written quite a while ago now and can be found at CodeGuru. This version, however, has a lot more functionality. New features include:

    • Floating Point display
    • Time Display
    • Bug fixed: Memory leak in Draw() function
    • Mouse interaction (optional) with the ability to make large & small changes, and these changes adapt to whether the control is in 'float' or 'integer' mode.
    • 3D Progress bar class (I 'borrowed' the technique from the very cool progress control by Paul Meidinger) which I implemented as a separate class for max re-use
    • Built-in (optional) notification. Trap WM_UPDATE_STATIC messages in your dialog and get up-to-date change notifications when user interacts with the control.
    • Supply ID's to each or any of your CStaticCounter controls to enable you to identify them upon trapping the WM_UPDATE_STATIC message
    • Set (optional) blank padding for either float or integer displays
    • Define your own format strings to further customise the output display of the CStaticCounter

    The class also uses static control's dimensions to calculate metrics, which means it'll draw well formed digits with minimal intervention, regardless of the control's size.

    How to use the CStaticCounter

    If the control is being used to display integer values:

    Single Click Left Mouse Button:Decreases the value by 1
    Single Click Right Mouse Button:Increases the value by 1
    Left Mouse Button and drag:Increases or decreases by (mouse distance*1)
    Right Mouse Button and drag:Increases or decreases (mouse distance*0.01) - but displays a whole number

    If the control is being used to display floating point values:

    Single Click Left Mouse Button:Decreases the value by 0.01
    Single Click Right Mouse Button:Increases the value by 0.01
    Left Mouse Button and drag:Increases or decreases by (mouse distance*1)
    Right Mouse Button and drag:Increases or decreases (mouse distance*0.01)

    Display Related Methods

    void Display(CString strDisplay) 

    This function will display your string in a digital counter style, ignoring all characters except: 0 1 2 3 4 5 6 7 8 9 . :

    void Display(UINT uSecs=0, UINT uMins=0, UINT uHours=0, UINT uDays=0, 
                 CString strFormat="%D:%H:%M:%S") 

    This function enables you to simply tell the control to display, for instance, 5196 seconds by simply typing Display(5196). The output will be displayed in D:H:M:S format unless you change the format string (last parameter) accordingly.

    void DisplayCurrentTime(CString strFormat = "%H:%M:%S") 

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Jason Troitsky



    United Kingdom United Kingdom

    Member



    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    Generalvery good,thanks Pinmemberhpxs18:28 16 Oct '08  
    GeneralUtilizing in VB.net 2005 Pinmembermrwu2118:15 28 Apr '08  
    GeneralRe: Utilizing in VB.net 2005 PinmemberLiu Xia1:31 7 May '08  
    GeneralAdding a label PinmemberAnders Gustafsson5:25 22 Oct '07  
    GeneralThis is a perfect control! Pinmembermartintiger19:38 8 Aug '04  
    GeneralMemory DC Question Pinmemberalpha+8:01 3 Feb '02  
    GeneralExcellent control! PinsussTom Hunter10:15 23 Jan '00  
    GeneralRe: Excellent control! PinsussJason Hattingh23:44 23 Jan '00  
    Thank you for the compliments, Tom. I *haven't* tested it on windows 95, and I *have* tested it in NT 4 and Win98. To be honest I've never tried it with 256 colours either.
     
    The class has evolved a bit more since it was posted, since I've used it in a *real* project Smile | :)
     
    There is a colour difference (sometimes subtle) in release builds. I'm not sure why, but the fix is to turn global optimisations off at the beginning of the C3DBar.cpp and back on at the end....
     
    I will try to look at the 256 colour thang when I get a chance..
    GeneralRe: Excellent control! PinmemberTim Smith6:41 24 Mar '02  

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
    Web02 | 2.5.120529.1 | Last Updated 18 Jan 2000
    Article Copyright 2000 by Jason Troitsky
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid