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 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

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

SetText

void SetText(LPCTSTR lpszText);

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

Format

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.

SetColor

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.

GetOnColor

COLORREF GetOnColor() const

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

GetOffColor

COLORREF GetOffColor() const

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

SetDrawImmediately

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.

SetBkColor

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.

SetTransparent

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.

ModifyDigiStyle

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:

History

Version

Comments

1.0 February 2000

First 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 2001

Use 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 2002

Added 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 2002

Added 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"

For compile in Visual Studio 2005:
Add "int iChar" in for loop in file Digistatic.cpp(1035)

Have got a memory leak, show by MFC memory leak tracking in function :
CDSegment CDSegment::operator=(const CDSegment &Segment)
at pNewPoints = new CPoint[m_nCount]; and pNewTypes = new BYTE[m_nCount];

CDSegment CDSegment::operator=(const CDSegment &Segment) makes a deep copy together with the copy contructor. The function CDSegment::FreeSegment() deletes the old buffers. So basically there is no memory leak . Look for "deep copy" in a C++ textbook for more information

Enjoy the control

Michel WassinkWe must make user friendly software. Where are friendly users?

Can you describe how you create the control? Please try the demo apllication to see if it shows the same problem. How do you detect the memory loss?
You can also send me some code which gives the problem.

I hope I can help you with your problem.

regards,

Michel WassinkWe must make user friendly software. Where are friendly users?

Thank you for pointing this out. The code seems to be not fully unicode compliant.
To resolve this, change all literal strings from "" to _T("")
and strcpy() to _tcscpy()
Then everything will compile just fine.

regards,

Michel WassinkWe must make user friendly software. Where are friendly users?

Hello,
I added the 6 files in question into my foldar that contains the source code for my current project. In Visual Studio I then went into the file menu and selected "Add existing item" for each of the 6 files in question. I then tried to build my code as it currently existed, just to verify that adding the new routines would not cause a problem. I then received 102 compilation errors and 3 warnings.

I'll include the entire list in case anyone is out there that has worked through this before.

When building digistatic.cpp, the first file it includes is stdafx.h.
Normally with appwizard generated apps Microsoft will include which defines the CDC object and will not give you compilation errors.

Try to compile the Demo application too and check if you get the same errors.

regards,

Michel WassinkWe must make user friendly software. Where are friendly users?

The only changes that I have made since then was to add afxwin.h in both MemDC.h and DigiStatic. This got rid of the compilation errors but then resulted in the linker errors that I am now getting.

I went back to the original counter project that you supplied. I am able to both build and run your project without having to include afxwin.h in the files that I mentioned above. I guess I need to look through the linker properties to verify that all the settings are the same?

I just want to have numerous displayed values, exactly like the 56.873 that you have in the upper right corner. These will be showing voltage and temperature levels for our experiment. I looked through the code and it seems like it should be very easy to do once I figure out the linker errors.

Could the errors be the result of some kind of conflict or duplication with all the libraries that I seem to be including? This is my first Visual C++ project so I'm pretty unfamiliar with this and I could very well be off on the wrong track.