home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / util / super_c / bord3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-01  |  2.9 KB  |  71 lines

  1. /*              Change Border Color from Keyboard
  2.  
  3.         This program changes the background color/attributes.
  4. */
  5.  
  6. #define TRUE 1
  7. #define FALSE 0
  8.  
  9. /*      main(argc,argv)
  10.  
  11.         Function: Watch the keyboard and change the attributes of each
  12.         character on the display based on the current state of the shift, 
  13.         control and alt keys. The low four bits of the attributes are to
  14.         be set to the current shift state; the upper four bits are set from
  15.         the shift state when the space bar is pressed. Exit when any key 
  16.         other than the space bar is pressed.
  17.  
  18.         Algorithm: Repeatedly call keyChk to see if something other than
  19.         shift keys are pressed. If not, call keyShf to get the current
  20.         state of the shift keys; if they've changed, call getACh/putACh
  21.         for each character on the display.
  22. */
  23.  
  24. main(argc,argv)
  25.  
  26. int argc;
  27. char *argv[];
  28.  
  29. {
  30.         int key;                        /* Key pressed. */
  31.         char curAttr, lastAttr;         /* Current and last attribute. */
  32.         char ch, attr;                  /* Char and attribute from display. */
  33.         int i,j;                        /* Row and column indices. */
  34.  
  35.         /* Set the attribute to white on black. */
  36.         lastAttr = 7;
  37.  
  38.         /* Repeatedly call keyChk to see if anything non-shift was pressed. */
  39.         while (TRUE) {
  40.                 /* Assume the top bits stay the same as they were. */
  41.                 curAttr = lastAttr & 0xF0;
  42.                 /* Check for a key press. */
  43.                 if (keyChk(&key)) {
  44.                         /* If yes, check for the space bar. */
  45.                         if ((key & 0xFF) == ' ') {
  46.                                 /* If yes, clear the key from the queue. */
  47.                                 keyRd();
  48.                                 /* Set the new top of the attribute. */
  49.                                 curAttr = (keyShf() << 4) & 0xF0;
  50.                         /* Otherwise, exit the loop. */
  51.                         } else break;
  52.                 };
  53.                 curAttr |= keyShf() & 0xF;
  54.                 /* If we've got a new attribute, set all the characters
  55.                    to it. */
  56.                 if (curAttr != lastAttr)
  57.                         for (i = 0; i < 24; i++)
  58.                                 for (j = 0; j < 79; j++) {
  59.                                         /* Position the cursor. */
  60.                                         setPos(0,i,j);
  61.                                         /* Get the old character/attribute. */
  62.                                         getACh(0,&ch,&attr);
  63.                                         /* Put the new character/attribute. */
  64.                                         putACh(0,ch,curAttr,1);
  65.                                         /* Remember the new attribute. */
  66.                                         lastAttr = curAttr;
  67.                                 };
  68.          };
  69. }
  70.  
  71.