Dec 212017
 
Borland C++ OWL example of a TWindow derived type that displays an LED digit in a child window.
File LED.ZIP from The Programmer’s Corner in
Category C++ Source Code
Borland C++ OWL example of a TWindow derived type that displays an LED digit in a child window.
File Name File Size Zip Size Zip Type
LED.CPP 3580 1284 deflated
LED.EXE 68813 20100 deflated
LED.ICO 766 159 deflated
LED.PRJ 6275 1370 deflated
LED.RC 331 128 deflated
LED0.BMP 302 103 deflated
LED1.BMP 302 98 deflated
LED2.BMP 302 107 deflated
LED3.BMP 302 100 deflated
LED4.BMP 302 112 deflated
LED5.BMP 302 109 deflated
LED6.BMP 302 104 deflated
LED7.BMP 302 107 deflated
LED8.BMP 302 94 deflated
LED9.BMP 302 107 deflated
LEDCOL.BMP 302 111 deflated
LEDWIND.CPP 9714 3070 deflated
LEDWIND.TXT 4654 1765 deflated
TURBOC.CFG 77 45 deflated

Download File LED.ZIP Here

Contents of the LEDWIND.TXT file



Definition of Class LEDDigit

LEDDigit is derived from TWindow, and represents an LED Digit within
a LEDWindow object.


Data Member:

HBITMAP hCurrentLEDBmp;

hCurrentLEDBmp is a handle to a bitmap resource which contains the
bitmap of the LED digit that is currently displayed by this LEDDigit
object.


Member functions:

constructor

LEDDigit( PTWindowsObject AParent, int DigitXLoc, BOOL bSurround,
HBITMAP hLEDBmp );

Constructs a LEDDigit object within the parent window (AParent),
at X offset DigitXLoc. If bSurround is TRUE, the X and Y locations
of this object within the parent are modified to account for the
pixels used by the surround (DigitXLoc also changes). hLEDBmp is
the handle of the initial LED bitmap to be displayed by this object.

UpdateDigit

void UpdateDigit( HBITMAP hLEDBmp );

Updates the current LED bitmap to be displayed (hLEDBmp).

Paint

virtual void Paint( HDC PaintDC, PAINTSTRUCT _FAR &PaintInfo );

Paints (with a BitBlt) the current digit in the LEDDigit window.

----------------------------------------------------------------------------

Definition of Class LEDWindow

Data Members:

HBITMAP hLEDBmp[11];

An array of handles for the bitmaps of the LED digits 0 - 9 and :.

BOOL bTimerActive;

If TRUE, a timer has been started for the window, and Tick will be
called every nTimerInterval seconds.

BOOL bSurroundExists;

If TRUE, a chisled surround is required by this LEDWindow.

BOOL bClockWindow;

If TRUE, this is an HH:MM:SS clock. In which case the LEDWindow is
8 digits long and is displayed using localtime to convert from date
(seconds since 1 Jan 1970) to HH:MM:SS.

BOOL bLEDCreated;

A first-time switch used by the constructor to tell SetUpLEDs not to
bother to invalidate the LEDDigits this time.

LONG lLEDValue;

The current value of this LEDWindow, either a LONG integer, or a time
(which equates to LONG).

struct tm *tmLEDValue;

Time structure used to format times into HH:MM:SS for display.

int nOldDigit[10];

The 'old' contents of the various LED digits, used by SetUpLEDS to
determine which LEDs to invalidate for display.

int nMaxDigits;

The maximum number of digits that this LEDWindow can display. There is
no supression of leading zeros in an LEDWindow, so nMaxDigits is also
the actual number of digits displayed.

int nTimerInterval;

The time in seconds between Ticks (WM_TIMER messages) for this LEDWindow.
Must be 0 (no timer) or between 1 and 60. No sub-second times are catered
for.

int nDigitStart;

The start (X) location of digits within this LEDWindow.

int nRow, nCol;

The row and column offset of this LEDWindow within the parent window.

LEDDigit *hLED[10];

An array of handles to the LEDDigit objects which are children of this
LEDWindow.
Note: LEDDigits are right to left: *hLED[0] (and nOldDigit[0]) is
the right-most (ones) digit.


Member functions:

constructor

LEDWindow( PTWindowsObject AParent, int x, int y,
int nDigits, BOOL bSurround, BOOL bClock, LONG lValue );

Creates an LEDWindow within parent AParent at row x, column y. The
LED has nDigits numerals. If bSurround is true, a chiseled surround
is drawn around the number. If bClock is TRUE, the LED is an HH:MM:SS
clock. lValue contains the time or number to be displayed by this LED.

destructor

~LEDWindow( void );

Cleans up by destroying the bitmaps loaded in the constructor.

void GetWindowClass(WNDCLASS& AWndClass);

Modifies the standard TWindow class definition to include a GRAY
background.

void DisplayNumber( LONG lValue );

Displays lValue in the LED. If bClock is true, adds 18000 to lValue
if it is less than 1 'day' (86400 seconds) to prepare it for processing
by the localtime function.

BOOL StartTimer( int nInterval );

Starts a windows timer for the LEDWindow with an interval of nInterval
seconds.

void StopTimer( void );


Stops a timer for a LEDWindow (if one is active).

void SetupLEDs( void );

Decides which LEDs must be changes to reflect an updated lLEDValue.
Selects the appropriate bitmap and passes it to the LEDDigit.

virtual void Tick( RTMessage Msg ) = [WM_TIMER];

Called once for every WM_TIMER message sent to his LEDWindow. Adds one
to lLEDValue for each tick.

virtual void Paint(HDC PaintDC, PAINTSTRUCT&);

Paints the LEDWindow surround (if required).

----------------------------------------------------------------------------


 December 21, 2017  Add comments

Leave a Reply