home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 371_01 / exampl4.c < prev    next >
Text File  |  1991-12-26  |  2KB  |  80 lines

  1. /***************************************************************************
  2. * EXAMPL4.C
  3. * This example creates a non scrollable, cursor addressable window which
  4. * is programmed and looks just like an old fashion menu.
  5. ****************************************************************************/
  6.  
  7. #include <WinDosIO.h>
  8.  
  9. #define CURUP    72
  10. #define CURDWN    80
  11. #define HOME    71
  12. #define END    79
  13.  
  14. struct MENU {
  15.     char *entry;
  16.     char *popup;
  17.  } menu[] = {
  18. {"Apples","An apple a day keeps the doctor away"},
  19. {"Oranges","Orange you glad I didn't say banana"},
  20. {"Peanuts","For comic relief"},
  21. {"Kiwi","I don't eat birds or shoe polish"},
  22. {"Cashews", "God bless you"}};
  23.  
  24. short menuMax = sizeof(menu) / sizeof(struct MENU);
  25. short getkey(void);
  26.  
  27. struct text_info ti;
  28.  
  29.  
  30. main()
  31.  {
  32.     short i;
  33.     short holdLine;
  34.  
  35.     for (i = 0; i < menuMax; i++)
  36.         printf("%-13.13s[ ]\n",(char far *)menu[i].entry);
  37.     gotoxy(15,1);
  38.     for(;;)
  39.          {
  40.         short k = getkey();
  41.         if (k < 0) break;
  42.         switch (k)
  43.          {
  44.            case CURDWN:
  45.             if (wherey() < menuMax) gotoxy(15,wherey()+1);
  46.                 break;
  47.            case CURUP:
  48.             if (wherey() > 1) gotoxy(15,wherey()-1);
  49.                 break;
  50.            case HOME:
  51.             gotoxy(15,1);
  52.                  break;
  53.            case END:
  54.             gotoxy(15,menuMax);
  55.                 break;
  56.            default:
  57.             holdLine = wherey();
  58.             gettextinfo(&ti);
  59.             window(20,10,60,10);
  60.             clrscr();
  61.             printf("%s",(char far *)menu[holdLine-1].popup);
  62.             window(ti.winleft,ti.wintop,ti.winright,ti.winbottom);
  63.             gotoxy(ti.curx,ti.cury);
  64.             break;
  65.         }
  66.      }
  67.     return 0;
  68.  }
  69.  
  70. short getkey(void)
  71.  {
  72.     int k = getch();
  73.     if (!k)
  74.          return getch();
  75.     return k;
  76.  }
  77.  
  78.  
  79.  
  80.