home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap11 / scrmenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-06  |  1.8 KB  |  80 lines

  1. /* scrmenu.c  -- uses bit fields to modify your text   */
  2. /*               screen's attributes                   */
  3.  
  4. char *Choice_Words[] = {
  5.     "Quit",
  6.     "Foreground",
  7.     "Intensity",
  8.     "Background",
  9.     "Blinking"
  10. };
  11. enum Choices { 
  12.     Quit, 
  13.     Foreground, 
  14.     Intensity, 
  15.     Background, 
  16.     Blinking 
  17. };
  18.  
  19. /* use 0xB800000 for EGA or VGA */
  20. #define SCR_START (0xB0000000)
  21. #define SCR_SIZE (25 * 80)
  22.  
  23. main()
  24. {
  25.     enum Choices choice;
  26.  
  27.     printf("Select from the following by number:\n");
  28.  
  29.     for (choice = Quit; choice <= Blinking; ++choice)
  30.         {
  31.         printf("%d. %s\n", choice, Choice_Words[choice]);
  32.         }
  33.  
  34.     printf("\nWhich: ");
  35.     do 
  36.         {
  37.         choice = getch();
  38.         choice -= '0';
  39.         if (choice < Foreground || choice > Blinking)
  40.             continue;
  41.         Redraw(choice);
  42.         } while (choice != Quit);
  43.  
  44. }
  45.  
  46. Redraw(enum Choices field)
  47. {
  48.     struct screen_char {
  49.         unsigned int character  :8,
  50.                      foreground :3,
  51.                      intensity  :1,
  52.                      background :3,
  53.                      blink      :1;
  54.     } scrchar, far *sp, far *ep;
  55.  
  56.     sp = (struct screen_char far *)SCR_START;
  57.     ep = sp + SCR_SIZE;
  58.  
  59.     while (sp < ep)
  60.         {
  61.         scrchar = *sp;
  62.         switch (field)
  63.             {
  64.             case Foreground:
  65.                 scrchar.foreground = (scrchar.foreground)? 0 : 7;
  66.                 break;
  67.             case Intensity:
  68.                 scrchar.intensity = (scrchar.intensity)? 0 : 1;
  69.                 break;
  70.             case Background:
  71.                 scrchar.background = (scrchar.background)? 0 : 7;
  72.                 break;
  73.             case Blinking:
  74.                 scrchar.blink = (scrchar.blink)? 0 : 1;
  75.                 break;
  76.             }
  77.         *(sp++) = scrchar;
  78.         }
  79. }
  80.