home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / c / sclib31 / examples / menubar1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-31  |  4.7 KB  |  193 lines

  1. #include <scl1.h>
  2. #include <scl1keys.h>
  3. #include <scl1clor.h>
  4.  
  5.     /**********************
  6.       MenuSystem example  */
  7.  
  8. MSBar msb[]={
  9.  
  10. /* Menu-bar data:
  11.      Start and end column of each option
  12.      Menu's key SCAN-ASCII code
  13.      String */
  14.  
  15.      1,6,0x2100," File ",
  16.      7,12,0x1200," Edit ",
  17.      };
  18.  
  19. /* first pull-down menu
  20.      row, column position
  21.      string
  22.      hot-key */
  23.  
  24. MSOptions mso0[]={
  25.      2,1," Load ",'L',
  26.      3,1," Save ",'S',
  27.      4,1," Quit ",'Q',
  28.      };
  29.  
  30. /* second pull-down menu */
  31.  
  32. MSOptions mso1[]={
  33.      2,7," Mark  ",'M',
  34.      3,7," Cut   ",'C',
  35.      4,7," Copy  ",'y',
  36.      5,7," Paste ",'P',
  37.      };
  38.  
  39. /* buffer for storing pull down menu screen area */
  40.  
  41. char WindowBuf[140];
  42.  
  43. /* Pull-down menu box & window information
  44.      top left corner and bottom right corner positions
  45.      number of options
  46.      buffer for saving screen area
  47.      MSOptions structure  */
  48.  
  49. MSWindow msw[]={
  50.      1,0,5,7,3,WindowBuf,mso0,
  51.      1,6,6,14,4,WindowBuf,mso1,
  52.      };
  53.  
  54. /* This structure links all previous structures */
  55.  
  56. MSData msd=
  57.      {
  58.    /* bar-menu colors */
  59.  
  60.      BLACK_WHITE,WHITE_BLACK+HIGHLIGHT,
  61.  
  62.    /* pull-down menu colors */
  63.  
  64.      WHITE_BLACK,BLACK_WHITE,WHITE_BLACK+HIGHLIGHT,
  65.  
  66.    /* MSBar, MSWindow structures, number of menus and internal variables */
  67.  
  68.      msb,msw,2,0,0,0};
  69.  
  70. main()
  71. {
  72. int Mess;
  73.  
  74. InitMouse(IM_SHOW); /* initialize mouse */
  75.  
  76. /* Draw shadows */
  77.  
  78. MenuSystem(MS_SHADOW_ON,(MSData *)0);
  79.  
  80. /* MenuSystem will be ALT sensitive */
  81.  
  82. MenuSystem(MS_ALT_ON,(MSData *)0);
  83.  
  84. /* draw */
  85.  
  86. MenuSystem(MS_DRAW,&msd);
  87.  
  88. do
  89.      {
  90.  
  91.      /* a key pressed? */
  92.  
  93.      if(Mess=KeyReady())
  94.           {
  95.  
  96.           /* send key to MenuSystem */
  97.  
  98.           Mess=MenuSystem(MS_KEY,&msd,Mess);
  99.  
  100.           /* If we still have a key it means it was not a MenuSystem key, 
  101.              discard key. If your program needs to service the keyboard you 
  102.              should do it here. */
  103.  
  104.           if(KeyReady())
  105.                GetKey();
  106.           }
  107.      else
  108.  
  109.           /* Let MenuSystem check if the mouse has been clicked
  110.              or a selection has been made */
  111.  
  112.           Mess=MenuSystem(MS_CHECK,&msd);
  113.  
  114.      if(Mess==MS_SELECT)
  115.           {
  116.  
  117.           /* a selection was made, msd.Menu=selected menu */
  118.  
  119.           switch(msd.Menu)
  120.                {
  121.                case 1:
  122.  
  123.                /* first menu, msd.Option=selected option */
  124.  
  125.                     switch(msd.Option)
  126.                          {
  127.                          case 1:
  128.  
  129.                               /* first option */
  130.  
  131.                               MessageOn(BLACK_WHITE,"Load");
  132.                               WaitTime(100);
  133.                               MessageOff();break;
  134.  
  135.                          case 2:
  136.  
  137.                               /* second option */
  138.  
  139.                               MessageOn(BLACK_WHITE,"Save");
  140.                               WaitTime(100);
  141.                               MessageOff();break;
  142.                          case 3:
  143.  
  144.                               /* third option */
  145.  
  146.                               MessageOn(BLACK_WHITE,"Quit");
  147.                               WaitTime(100);
  148.                               MessageOff();
  149.                               break;
  150.                               }
  151.                     break;
  152.  
  153.                case 2:
  154.  
  155.                     /* second menu */
  156.  
  157.                     switch(msd.Option)
  158.                          {
  159.                          case 1:
  160.                               /* first option */
  161.  
  162.                               MessageOn(BLACK_WHITE,"Mark");
  163.                               WaitTime(100);
  164.                               MessageOff();
  165.                               break;
  166.  
  167.                          case 2:
  168.                               /* second option */
  169.  
  170.                               MessageOn(BLACK_WHITE,"Cut");
  171.                               WaitTime(100);
  172.                               MessageOff();
  173.                               break;
  174.                          case 3:
  175.                               /* third option */
  176.  
  177.                               MessageOn(BLACK_WHITE,"Copy");
  178.                               WaitTime(100);
  179.                               MessageOff();
  180.                               break;
  181.                          case 4:
  182.                               /* fourth option */
  183.  
  184.                               MessageOn(BLACK_WHITE,"Paste");
  185.                               WaitTime(100);
  186.                               MessageOff();
  187.                               break;
  188.                          }
  189.                     break;
  190.                }
  191.           }
  192.      }while(msd.Menu != 1 || msd.Option != 3);
  193. }