home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / pcw_c.zip / PDEMO.C < prev    next >
Text File  |  1990-01-30  |  5KB  |  106 lines

  1. /***********************************************************/
  2. /* Program Id.               PmnuDemo.C.                   */
  3. /* Author.                   Stan Milam.                   */
  4. /* Date Written.             03/12/89.                     */
  5. /*                                                         */
  6. /* Comments: This program demonstrates the use of the pop- */
  7. /* up menu capabilities of PC Windows.  Use the up & down  */
  8. /* arrow keys to change the selection. Press enter to make */
  9. /* a selection.  Or, press 1 thru 5 to select, or use the  */
  10. /* mouse to "point and shoot".                             */
  11. /***********************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <pcwproto.h>
  15. #include <menu.h>
  16.  
  17. int pmenu_demo(void) {
  18.  
  19.    WNDPTR *wnd, *savewnd, *iwnd;
  20.  
  21. /***********************************************************/
  22. /* Initialize the popup menu structures defined in menu.h. */
  23. /***********************************************************/
  24.  
  25.    static PMNUFLDS pitems[] = {
  26.        { '1', "1. Methodology                   "},
  27.        { '2', "2. Word Processors               "},
  28.        { '3', "3. ITI Mainframe Communications  "},
  29.        { '4', "4. C Programming Environment     "},
  30.        { '5', "5. Pascal Programming Environment"},
  31.        { 'e' ,"E. Esc or Right Mouse Key - Exit "},
  32.        {  0,  ""}
  33.     };
  34.  
  35. /**********************************************************/
  36. /* PMNUTYPE contains elements concerning a popup menu.    */
  37. /* First, there is a pointer to the window to be used,    */
  38. /* then window parameters, border parms, title parms,     */
  39. /* selection bar parms, and finally a pointer back to our */
  40. /* menu options.                                          */
  41. /**********************************************************/
  42.  
  43.     static PMNUTYPE  pmenu =  {
  44.        NULL,
  45.        13, 20, 20, 60, BLACK,LIGHTGRAY,          /* Window Parms */
  46.        2, RED,LIGHTGRAY,                         /* Border Parms */
  47.        " Main Menu ",TOP,MIDDLE,BLUE,LIGHTGRAY,  /* Title  Parms */
  48.        WHITE,BLUE,0,                             /* Select Bar   */
  49.        pitems                                    /* pointer to menu list */
  50.     };
  51.  
  52.     static char *instructions[] = {
  53.        "To use the  Popup  Menu  use  the  \30\31  arrow  keys,",
  54.        "to place the cursor bar on  the  desired  selection",
  55.        "and then press enter.  Or, use the SELECT CHARACTER",
  56.        "at left of each selection, or...use  the  Mouse  to",
  57.        "point and shoot the selection you want.  ESC or the",
  58.        "right Mouse key will end the demo.                 ",
  59.        NULL
  60.     };
  61.  
  62.     static char *selections[] = {
  63.        "Methodology",
  64.        "Word Processors",
  65.        "ITI Mainframe Communications",
  66.        "C Programming Environment",
  67.        "Pascal Programming Environment"
  68.     };
  69.  
  70.     int i = 0;
  71.     int mxr, mxc;
  72.  
  73.    chk_video_state(&mxr,&mxc);                   /* Get max rows & cols */
  74.    savewnd = wpush(1,1,mxr,mxc);                 /* Save entire screen */
  75.    if (!savewnd) return(3);                      /* Exit if cannot save */
  76.    bordercolor(BLUE,LIGHTGRAY);                  /* Set border color */
  77.    titlecolor(BLACK,LIGHTGRAY);                  /* Set the title color */
  78.    iwnd = wexplode(2,10,11,70,RED,LIGHTGRAY);      /* Make instruction window */
  79.    wtitle(iwnd,TOP,LEFT," Popup Menu Instructions "); /* Title it */
  80.    w_block_write(iwnd, 2, CENTER,instructions);  /* Write instructions to it */
  81.    wnd = makepmenu(&pmenu);                      /* Make a popup window */
  82.    while (i != 27 && i != 'e') {                 /* Do until Esc */
  83.       i = pmenuinput(&pmenu);                    /* Get Menu return value */
  84.       switch(i) {
  85.          case '1' :
  86.          case '2' :
  87.          case '3' :
  88.          case '4' :
  89.          case '5' :
  90.             if (mpresent) hide_mouse();
  91.             i -= 48;
  92.             qhchar(22,1,7,BLUE,176,80);          /* Clear msg line */
  93.             qputs(22,99,RED,7,selections[i-1]);  /* Write the choice */
  94.             if (mpresent) show_mouse();
  95.             break;
  96.          default: break;
  97.       }
  98.    }
  99.    if (mpresent) hide_mouse();                   /* Hide the mouse */
  100.    wnd     = wpop(wnd);                          /* Get rid of menu */
  101.    iwnd    = wpop(iwnd);                         /* Get rid of instructions */
  102.    savewnd = wpop(savewnd);                      /* Restore msg row */
  103.    return(0);                                    /* And go home */
  104. }
  105.  
  106.