Click here to Skip to main content
15,867,453 members
Articles / Desktop Programming / MFC
Article

Digital Display CStatic control

Rate me:
Please Sign up or sign in to vote.
4.98/5 (60 votes)
9 Nov 2002CPOL6 min read 237.6K   10.9K   177   47
An article on the Digital Display Control

Sample Image

Introduction

This control is derived from CStatic. It is bitmap-based to make it easy for the user to alter the character set. Three sized character sets are provided as can be seen in the example above. Features are:

  • Bitmapped based for easy altering of character set.
  • Single or multilined displays.
  • Scrolling left, right, up or down at various speeds.
  • Class is derived from CStatic and is easy to use.
  • All colours can be very easily changed.
  • Three character sizes are provided
  • Optional automatic sizing of CStatic control
  • Optional auto padding of strings with a supplied character
  • Support for altering format of supplied bitmap.

Class Members

MatrixStatic::SetAutoPadding

This function pads the internal display string (set with the SetText() function) with a supplied character so that it equals the length of the value supplied in the SetXCharsPerLine() function.

void SetAutoPadding(
   bool pad,
   char ch = ' ');

Parameters

pad - A C++ boolean variable. true = Strings will be automatically padded with the given character to equal the value supplied to the class in the SetXCharsPerLine() function. false = No auto padding will occur.

ch - a char variable. This parameter is optional as it defaults to a space character. This is the character used to pad the string if the above parameter is true.

Return Value

None

MatrixStatic::GetText

This function fills a supplied buffer with the text that was set in the SetText() function.

int GetText(
	char *string,  
	int size);

Parameters

string - A pointer to a buffer the requested text will be placed in to.

size - An integer containing the length of the supplied buffer.

Return Value

Function returns an integer of the number of characters placed in the buffer.

MatrixStatic::SetDisplayColors

This function sets all three colours of the display characters in a single function call.

void SetDisplayColors(
	COLORREF bk,  
	COLORREF on,  
	COLORREF off);

Parameters

bk - A COLORREF variable which supplies the RGB(x, x, x) value of the background colour of the display.

on - A COLORREF variable which supplies the RGB(x, x, x) value of the on colour of the display.

off - A COLORREF variable which supplies the RGB(x, x, x) value of the off colour of the display.

Return Value

None

MatrixStatic::SetBkColor

This function sets the background colour of the display.

void SetBkColor(
	COLORREF bk);

Parameters

bk - A COLORREF variable which supplies the RGB(x, x, x) value of the background colour of the display.

Return Value

None

MatrixStatic::SetColor

This function sets the on and off colours of the display.

void SetColor( COLORREF off, COLORREF on);

Parameters

on - A COLORREF variable which supplies the RGB(x, x, x) value of the on colour of the display.

off - A COLORREF variable which supplies the RGB(x, x, x) value of the off colour of the display.

Return Value

None

MatrixStatic::SetBitmapResource

This function is optional. It allows for an alternate bitmap resource to be supplied. (See the supplied resource bitmaps which can be used as a template for new character formats.) There are three bitmap resources supplied that the program requires. The correct one to use is set when you call the SetSize() function. They must have the ID's of IDB_MATRIXLARGE, IDB_MATRIXSMALL and IDB_MATRIXTINY.

If this function is used to supply a new or different bitmap, even if the format is the same, you must also call the MatrixStatic::SetCustomCharSizes function to supply information about this bitmap.

void SetBitmapResource(
	UINT bitmap);

Parameters

bitmap - Resource identifier of the bitmap resource.

Return Value

None.

See Also

SetSize which identifies the different size bitmaps supported.

SetCustomCharSizes() which allows different format bitmaps.

MatrixStatic::SetText

This function supplies the text that is to be displayed. Once called your supplied string can be deleted, the text is stored in a member CString variable.

void SetText(
	LPCTSTR lpszText);

Parameters

lpszText - A 32-bit pointer to a constant character string

Return Value

None.

MatrixStatic::SetSize

This function identifies which of the three supported sized bitmaps was supplied in the SetBitMapResource() function.

void SetSize(
	int size = SMALL);

Parameters

size - an integer variable that identifies which of the three bitmap sizes supported was given in the SetBitMapResource() function. Possible values are LARGE, SMALL & TINY, which a defined within the class as 0, 1 and 2 integers respectively.

Return Value

None.

See Also

See the three supplied bitmap templates as an example of this.

SetCustomCharSizes() which allows custom format bitmaps.

MatrixStatic::StopScroll

This function ceases the scrolling of the display.

void StopScroll();

Parameters

None.

Return Value

None.

MatrixStatic::DoScroll

This function starts the display scrolling in the supplied direction. This is not a pixel scroll but a character scroll.

void DoScroll(
	int speed, 
	BOOL dir);

Parameters

speed - Speed of the scrolling in milliseconds. This is the same value you would supply to the Windows SetTimer() function.

dir - Direction of scroll. Possible values are:

Single Line Display: (SetNumberOfLines was supplied a value of 1) LEFT or RIGHT, defined within the class as boolean 0 or 1 respectively.

Multiline Display: (SetNumberOfLines was supplied a value greater than 1) UP, DOWN, LEFT or RIGHT, defined within the class as 0, 1, 2 or 3 respectively.

Return Value

None.

MatrixStatic::SetCustomCharSizes

This function allows you to use custom format bitmaps. It sets the pixel sizes of each character and the vertical and horizontal spacing.

These values are automatically filled in for the three internally supported sizes of bitmaps.

void SetCustomCharSizes(
	int width, 
	int height, 
	int xspace,  
	int yspace);

Parameters

width - An integer of the width of each character in pixels.

height - An integer of the height of each character in pixels.

xspace - An integer of the space between each character horizontally in pixels.

yspace - An integer of the space between each character vertically in pixels.

Return Value

None.

MatrixStatic::AdjustClientYToSize

This function allows the CStatic object to be automatically sized vertically for you to a given number of characters.

void AdjustClientYToSize(
	int size);

Parameters

size - number of vertical display lines you want the object sized to.

Return Value

None.

See Also

SetNumberOfLines()

SetXCharsPerLine()

SetAutoPadding()

AdjustClientXToSize

MatrixStatic::AdjustClientXToSize

This function allows the CStatic object to be automatically sized horizontally for you a given number of characters.

void AdjustClientXToSize(
	int size);

Parameters

size - number of characters you want the object sized to.

Return Value

None.

See Also

SetNumberOfLines()

SetXCharsPerLine()

SetAutoPadding()

AdjustClientYToSize()

MatrixStatic::SetNumberOfLines

This function sets the number of vertical display lines you want. It does not have to equal the length of the string divided by the MaxXChars value. This is useful for vertical scrolling. If the string is longer than the number of characters shown in a multiline display and vertical scrolling is enabled, the display will scroll through the string showing all characters. An example of this is in the project example.

void SetNumberOfLines(
	int max = 0);

Parameters

max - An integer that supplies the number of lines you want on the display.

Return Value

None.

See Also

SetXCharsPerLine()

SetAutoPadding()

AdjustClientXToSize

AdjustClientYToSize

MatrixStatic::SetXCharsPerLine

This function sets the number of characters horizontally in the display. In a single line display it sets how many characters can be seen in the display at one time. On multiline displays it sets how many horizontal characters are to be used on each line.

For example: If you wanted three lines of ten characters each, a string of 30 characters would be supplied in the SetText() function. This parameter would be set to 10, and the SetNumberOfLines() function would be supplied with 3.

The difference between single and multiline is: Single line displays can have a string longer than the supplied parameter and only the number of characters supplied here will be shown. Multiline displays cannot, The next line displayed starts at the character following the number of characters supplied here.

void SetXCharsPerLine(
	int max = 0);

Parameters

None.

max - An integer that supplies the number horizontal characters to display.

Return Value

None.

See Also

SetNumberOfLines()

SetAutoPadding()

AdjustClientXToSize()

AdjustClientYToSize()

History

V1.0 initial release 11th November 2002

License

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


Written By
Web Developer
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
BugTry to display char ':' but result to ';' Pin
eeyrw25-Jul-14 18:09
eeyrw25-Jul-14 18:09 
GeneralMy vote of 5 Pin
evan36921-Jun-11 16:46
evan36921-Jun-11 16:46 
Answersolution for display no text Pin
Achillean4-Sep-08 3:29
Achillean4-Sep-08 3:29 
GeneralFlicker free paint Pin
mijalko19-Apr-06 1:26
mijalko19-Apr-06 1:26 
GeneralGreat code but..... Pin
Tim Moody5-Aug-05 4:55
Tim Moody5-Aug-05 4:55 
GeneralRe: Great code but..... Pin
newstar00821-Nov-05 23:24
newstar00821-Nov-05 23:24 
GeneralRe: Great code but..... Pin
liu08131-Dec-05 1:22
liu08131-Dec-05 1:22 
GeneralRe: Great code but..... Pin
gehlhajo13-Feb-06 1:57
gehlhajo13-Feb-06 1:57 
GeneralGreat code, but..... Pin
Tim Moody4-Aug-05 10:39
Tim Moody4-Aug-05 10:39 
Questionhow to export to a bitmap? Pin
Bloobird023-May-05 22:34
Bloobird023-May-05 22:34 
AnswerRe: how to export to a bitmap? Pin
Nic Wilson3-Jun-05 12:06
Nic Wilson3-Jun-05 12:06 
GeneralDo have ActiveX version for VB Pin
sanong25-Dec-04 5:52
sanong25-Dec-04 5:52 
It would be nice if we have activex version.
Blush | :O
Questionhow does it map? Pin
abstarsss6-Nov-04 12:07
abstarsss6-Nov-04 12:07 
AnswerRe: how does it map? Pin
Nic Wilson8-Nov-04 13:47
Nic Wilson8-Nov-04 13:47 
GeneralRe: how does it map? Pin
abstarsss10-Nov-04 19:55
abstarsss10-Nov-04 19:55 
GeneralIn chinese Pin
Anonymous18-Jul-04 5:32
Anonymous18-Jul-04 5:32 
GeneralRe: In chinese Pin
Nic Wilson4-Aug-04 15:35
Nic Wilson4-Aug-04 15:35 
GeneralRe: In chinese Pin
newstar0081-Nov-05 15:43
newstar0081-Nov-05 15:43 
QuestionGraphic capability? Pin
Anonymous13-Jul-04 10:29
Anonymous13-Jul-04 10:29 
AnswerRe: Graphic capability? Pin
Nic Wilson13-Jul-04 12:10
Nic Wilson13-Jul-04 12:10 
GeneralTo use more then ASCII codes Pin
Eugene Pustovoyt27-Apr-04 1:34
Eugene Pustovoyt27-Apr-04 1:34 
GeneralThats Wonder!!! Pin
Balkrishna Talele16-Feb-04 22:51
Balkrishna Talele16-Feb-04 22:51 
GeneralAbsolutely Fantastic Pin
Peter Coppinger21-Nov-03 8:17
Peter Coppinger21-Nov-03 8:17 
GeneralGreat Work! Pin
Anonymous12-Oct-03 4:02
Anonymous12-Oct-03 4:02 
GeneralRe: Great Work! Pin
liu08131-Dec-05 1:46
liu08131-Dec-05 1:46 

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.