home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD2.mdf
/
c
/
library
/
mslang
/
cp1
/
fill1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-01
|
3KB
|
107 lines
===========================================================================
BBS: The Abacus * HST/DS * Potterville MI
Date: 05-28-93 (07:58) Number: 223
From: BRENDA HOLLOWAY Refer#: NONE
To: ROBERT CADENA Recvd: NO
Subj: Windows from TP to TC Conf: (36) C Language
---------------------------------------------------------------------------
BH->character is an attribute byte. The low order byte of each
BH->word is the character, the high byte of each word is the
BH->attribute for the character.
RC> Thank you... I'm kinda new to TC so how do you change/read bytes...
Like this! <g>
/* Fills a window on the screen with a line of text */
/* Demo program for C_ECHO by Brenda Holloway. */
#include <conio.h>
#include <stdlib.h>
/* The "glom" macro gloms together the character and attribute into
an unsigned short integer, like the screen memory uses.
*/
#define glom( ch, attr ) ( (unsigned)(ch) | ((unsigned)(attr)<<8) )
/* WHITE_ON_RED uses constants from conio.h to form an attribute;
the bottom four bits are the foreground color, the next three the
background color, and the high bit, if on, blinks the character.
*/
#define WHITE_ON_RED ( WHITE | (RED<<4) )
/* Prototype for PutDemo. */
void PutDemo( int left, int top, int right, int bottom, char *s );
/* main. Clear the screen, put the block of text on the screen,
prompt the user, wait for a key, and hit the road.
*/
void main()
{
clrscr();
PutDemo( 10, 10, 40, 20, "I can C so very clearly " );
gotoxy(1,24);
cputs( "Hit nearly any key to continue..." );
getch();
}
/* PutDemo. Takes a window on the screen defined by left, top, right,
and bottom, and fills it with the string in 's' in white-on-red
characters.
*/
void PutDemo( int left, int top, int right, int bottom, char *s )
{
/* numChars - the number of characters to fill. */
int numChars = (right-left+1) * (bottom-top+1);
/* buffer - our screen buffer. Note that it's made of short
integers AND NOT characters, since that's how screen memory
actually looks.
*/
short *buffer = calloc( numChars, sizeof(short) );
/* If we got the buffer... */
if( buffer != NULL )
{
/* And there's anything to do... */
if( *s && numChars )
{
char *ps = s;
short i = 0;
/* Fill the buffer with the string */
while( i<numChars )
{
if( *ps == '\0' )
ps = s;
buffer[i++] = glom( *ps++, WHITE_ON_RED );
}
/* Blast it to the screen... */
puttext( left, top, right, bottom, buffer );
}
/* Free the buffer now. */
free( buffer );
}
}
--- Maximus 2.01wb
* Origin: Two Birds -- One Stone BBS (1:216/37)
SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
SEEN-BY: 153/752 154/40 77 157/110 159/100 125 575 950 203/23 209/209
SEEN-BY: 261/1023 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20