home *** CD-ROM | disk | FTP | other *** search
- /* MNEXAMPL.C: Simple example of Turbo C TOOLS menu usage. */
-
- #include <stdio.h>
- #include <bmenu.h>
- #include <bmouse.h>
-
- int main()
- {
- BMENU *pmenu;
- BORDER bord;
- WHERE location;
- int mode,columns,act_page;
- int cursor_was_off,cursor_row,cursor_col,high,low;
- int ercode,row,col,ch,keycode;
-
- /* Create the menu and window structures in memory. */
-
- pmenu = mncreate(3,15, /* Dimensions of window data area. */
- SC_CYAN, /* Attributes of normal menu items. */
- REVERSE, /* Attributes of highlight bar. */
- NORMAL, /* Attributes of protected items. */
- NORMAL); /* Attributes of item descriptions. */
-
- if (pmenu == NIL)
- return b_wnerr; /* Quit if failure. */
- /* (b_wnerr records the most */
- /* recent menu or window error.) */
-
- /* Build the menu items and assign keys to select them. */
-
- if (NIL == mnitmkey(pmenu,0,0,MN_NOPROTECT,"Yes","yY",MN_SELECT))
- return b_wnerr;
- if (NIL == mnitmkey(pmenu,1,0,MN_NOPROTECT,"No","nN",MN_SELECT))
- return b_wnerr;
- if (NIL == mnitmkey(pmenu,2,0,MN_NOPROTECT,"Maybe","mM",MN_SELECT))
- return b_wnerr;
-
- /* Choose style of border. */
-
- bord.type = BBRD_DDDD; /* Box drawn with double lines. */
- bord.attr = SC_MAGENTA; /* Border will be magenta on black. */
-
- /* Choose where to display the menu: the active page on the */
- /* current display device. */
-
- location.dev = scmode(&mode,&columns,&act_page);
- location.page = act_page;
- location.corner.row = 10;
- location.corner.col = 5;
-
- /* Turn mouse cursor on and choose a mouse style if mouse is */
- /* installed. */
-
- if (MO_OK == mohide(MO_SHOW))
- mnmstyle(pmenu,MN_MOU_CLICK,MO_LEFT);
- else
- printf("No mouse driver is installed.\n");
-
- /* Save former cursor position and size. */
-
- cursor_was_off = sccurst(&cursor_row,&cursor_col,&high,&low);
-
- /* Actually display the menu */
-
- if (NIL == mndsplay(pmenu,&location,&bord))
- return b_wnerr; /* Quit if failure. */
-
- /* Await the user's selection. Start the highlight bar at the */
- /* item located at (0,0). Beep if unknown keystrokes are */
- /* pressed. Discard the menu when done. */
-
- ercode = mnread(pmenu,0,0,&row,&col,&ch,&keycode,
- MN_UNKNOWN_BEEP | MN_DESTROY);
-
- /* Turn the mouse cursor back off. */
-
- mohide(MO_HIDE);
-
- /* Restore the cursor. */
-
- sccurset(cursor_row,cursor_col);
- scpgcur(cursor_was_off,high,low,CUR_NO_ADJUST);
-
- /* Report the user's selection: error code, final key, and */
- /* location of item selected. */
-
- printf("Error code from MNREAD: %d\n",ercode);
- printf("Keystroke: ch = %d, keycode = %d\n",ch,keycode);
- printf("Item location: row = %d, column = %d\n",row,col);
-
- return 0; /* Success. */
- }