COSC120 / Using the constream class for windowing and colors.

A library "constrea" contains procedures to use in windowing and using colors. The sample program TestWindo.CPP on the K drive in the demos folder illustrates the use of these subroutines. If you are interested in windowing and/or using colors, copy the demo program and play with it.

The constream stuff works just fine on SSU's network because SSU uses Borland C++ vers 5.01. However, Borland C++5.02 has an error in it which must be corrected before the constream class works properly. If you own your own copy of Borland C++ 5.02, you can make the correction yourself. It is described at the bottom of this document.

It is suggested that you use a piece of graph paper and mark off a rectangle 80 cells by 24 cells to represent the output screen. That way you can easily plan where you want your windows and where to place the cursor.

1. Include constrea.h at top of program, as in--
              #include <constrea.h>

2. Use the data type constream to represent a window, as in--
            constream win1;

3. Whenever you write to the window use the window's name instead of cout, as in--
            win1 << "Hello there!";

4. A window may be passed as a parameter but it must ALWAYS be passed by reference.

5. To define the window (using 80 columns and 24 rows), use the statement
            nameOfWindow.window(upLeftCol,upLeftRow,loRtCol,loRtRow);

            Ex: win1.window(5,4,40,12);         defines a window whose upper lefthand corner is at column 5, row 4 and
                                                                       whose lower righthand corner is at column 40, row 12.

6. To set the background color, use the statement--
            nameOfWindow << setbk(COLORNAME);         and then clear the screen as in nameOfWindow.clrscr();

            Ex: win1 << setbk(BLUE);
                  win1.clrscr();

7. To set the foreground color (the color for the text) use the statement--
            nameOfWindow << setclr(COLORNAME);

            Ex: win1 << setclr(MAGENTA);

8. To write to a window, use the statement --
            nameOfWindow << setxy(column,row) << "Text to be displayed...";

            The setxy(column,row) moves the cursor to that location. Otherwise, it will write to the current location.

            Ex: win1 << setxy(2,2) << "Hello there!";

9. To clear from the current cursor position to the end of the current line, using the statement nameOfWindow << clreol;
            Ex: win1<< setxy(12,4) << clreol;

10. To delete the current line, use the statement--
            nameOfWindow << delline;

            Ex: win1 << delline;

11. To insert a blank line above the cursor, leaving the cursor at the beginning of the new blank line, use the statement--
            nameOfWindow << insline;

            Ex: win1 << setxy(3,8) << insline;

12. Each color has a predefined constant in upper-case. The colors you may use for the background are:
            BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, & LIGHTGRAY.

            These represent color codes from 0 to 7, inclusive. Ex: BLUE has code 1.
            In order for the background color to take effect, you must clear the screen right away, as in--
                    win1 << setbk(GREEN);
                    win1.clrscr();

13. The colors you may use for the output are:
            All of those in #12 above plus DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED,
            LIGHTMAGENTA, YELLOW, and WHITE.

            These have color codes from 8 (DARKGRAY) to 15 (WHITE), inclusive.

            You may use the colors' codes instead of the constant names if you prefer, as in--
                    win1 << setbk (1);         instead of         win1 << setbk(BLUE);

            Keep in mind that certain color combinations don't work very well in terms of contrast (DARKGRAY on BROWN?).



Borland C++ 5.02 error :   (SSU uses version 5.01, which doesn't have this problem!)
Last modified by MLM 12/97.