Windows Pascal 1.5 - Text color & Background color

In the comp.lang.pascal.borland newsgroup Dmhusa wrote:
: I am converting some Pascal 3.0 programs to Win 1.5.
: I cannot locate the code to make my background color Red
: with white characters and Blue background & white char.

I think the simplest way to deal with this kind of thing
is to modify the WinCrt unit to do what you want done.

The source code is in the DOC directory:  DOC\WINCRT.PAS.

Copy the file to something appropriate:  MY_CRT.PAS
and change the UNIT line to match:       UNIT MY_CRT;

Add two variables (In the INTERFACE section if you want to change colours on
      the fly, or in the IMPLEMTATION section if the colours stay constant.)

Const TextColour : TColorRef = $FFFFFF {White}
      BackColour : TColorRef = $0000FF {Red}
      {TColorRef is 4 bytes: Alpha, Blue, Green, and Red.
       00 = Colour Gun OFF, FF=Colour Gun ON Full.
       (Alpha I don't understand, so I ignore it.)}

Now, in the Implementation section, you will have to set the drawing
colours everytime the program tries to draw.  The easiest way is to
modify the InitDeviceContext function.  (A device context is required
before Windows will do any drawing.)

Procedure InitDeviceContext;
  Begin
    If Painting
      Then DC := BeginPaint(CrtWindow,PS)
      Else DC := GetDC(CrtWindow);
    SaveFont := SelectObject(DC, GetSTockObject(System_Fixed_Font));
    SetTextColor(DC, TextColour); {New Line to set the Foreground Colour.}
    SetBKColor(DC, BackColour);   {New Line to set the Background Colour.}
  End;

You SHOULD also modify the initialization code at the end of the unit
from:   CrtClass.hbrBackground := GetStockObject(WhiteBrush);
to:     CrtClass.hbrBackground := CreateSolidBrush(BackColour);

However this will only have an effect if your window client area is
is larger than the screen size you have specified.
(For example:  ScreenSize.X:=35; WindowSize.X:=600;)

Warning:  If your program changes colours while it is running then this is
not yet entirely satisfactory.  If part of the window has to be repainted
(because it got overlapped by another window or moved offscreen), then the
text will be repainted in the current, not the original, colours.
If you NEED to tackle this problem ask and I might make some suggestions.

Conclusion:  It is relatively painless to modify the supplied units.
My WinCrt replacement unit supports colours, different text sizes,
function keys and arrow keys, and mouse clicks.  It also makes the
CrtWindow handle public so that I can use all the WinProcs procedures
on a WinCrt window.  You could even go on to modify WinProcs to fix
all those MicroSoft spelling errors - like the missing 'u' in colour!
 _
|/|\/|                          ||   Maths & Computer Science
|\|  |orew...@south.sd41.bc.ca  ||  Beautiful British Columbia
                                            (Canada)