home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 2.ddi / TOOLS.2 / EXAMPLES / MNEXAMPL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  2.9 KB  |  93 lines

  1.     /* MNEXAMPL.C:  Simple example of Turbo C TOOLS menu usage.     */
  2.  
  3. #include <stdio.h>
  4. #include <bmenu.h>
  5. #include <bmouse.h>
  6.  
  7. int main()
  8. {
  9.     BMENU  *pmenu;
  10.     BORDER  bord;
  11.     WHERE   location;
  12.     int     mode,columns,act_page;
  13.     int     cursor_was_off,cursor_row,cursor_col,high,low;
  14.     int     ercode,row,col,ch,keycode;
  15.  
  16.     /* Create the menu and window structures in memory.         */
  17.  
  18.     pmenu = mncreate(3,15,    /* Dimensions of window data area.  */
  19.         SC_CYAN,    /* Attributes of normal menu items. */
  20.         REVERSE,    /* Attributes of highlight bar.     */
  21.         NORMAL,     /* Attributes of protected items.   */
  22.         NORMAL);    /* Attributes of item descriptions. */
  23.  
  24.     if (pmenu == NIL)
  25.     return b_wnerr;     /* Quit if failure.            */
  26.                 /* (b_wnerr records the most        */
  27.                 /* recent menu or window error.)    */
  28.  
  29.     /* Build the menu items and assign keys to select them.        */
  30.  
  31.     if (NIL == mnitmkey(pmenu,0,0,MN_NOPROTECT,"Yes","yY",MN_SELECT))
  32.     return b_wnerr;
  33.     if (NIL == mnitmkey(pmenu,1,0,MN_NOPROTECT,"No","nN",MN_SELECT))
  34.     return b_wnerr;
  35.     if (NIL == mnitmkey(pmenu,2,0,MN_NOPROTECT,"Maybe","mM",MN_SELECT))
  36.     return b_wnerr;
  37.  
  38.     /* Choose style of border.                        */
  39.  
  40.     bord.type = BBRD_DDDD;    /* Box drawn with double lines.     */
  41.     bord.attr = SC_MAGENTA;    /* Border will be magenta on black. */
  42.  
  43.     /* Choose where to display the menu:  the active page on the    */
  44.     /* current display device.                        */
  45.  
  46.     location.dev    = scmode(&mode,&columns,&act_page);
  47.     location.page    = act_page;
  48.     location.corner.row = 10;
  49.     location.corner.col =  5;
  50.  
  51.     /* Turn mouse cursor on and choose a mouse style if mouse is    */
  52.     /* installed.                            */
  53.  
  54.     if (MO_OK == mohide(MO_SHOW))
  55.     mnmstyle(pmenu,MN_MOU_CLICK,MO_LEFT);
  56.     else
  57.     printf("No mouse driver is installed.\n");
  58.  
  59.     /* Save former cursor position and size.                */
  60.  
  61.     cursor_was_off = sccurst(&cursor_row,&cursor_col,&high,&low);
  62.  
  63.     /* Actually display the menu                    */
  64.  
  65.     if (NIL == mndsplay(pmenu,&location,&bord))
  66.     return b_wnerr;     /* Quit if failure.            */
  67.  
  68.     /* Await the user's selection.  Start the highlight bar at the  */
  69.     /* item located at (0,0).  Beep if unknown keystrokes are        */
  70.     /* pressed.  Discard the menu when done.                */
  71.  
  72.     ercode = mnread(pmenu,0,0,&row,&col,&ch,&keycode,
  73.             MN_UNKNOWN_BEEP | MN_DESTROY);
  74.  
  75.     /* Turn the mouse cursor back off.                    */
  76.  
  77.     mohide(MO_HIDE);
  78.  
  79.     /* Restore the cursor.                        */
  80.  
  81.     sccurset(cursor_row,cursor_col);
  82.     scpgcur(cursor_was_off,high,low,CUR_NO_ADJUST);
  83.  
  84.     /* Report the user's selection:  error code, final key, and     */
  85.     /* location of item selected.                    */
  86.  
  87.     printf("Error code from MNREAD:  %d\n",ercode);
  88.     printf("Keystroke:  ch = %d, keycode = %d\n",ch,keycode);
  89.     printf("Item location:  row = %d, column = %d\n",row,col);
  90.  
  91.     return 0;            /* Success.                */
  92. }
  93.