home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / VISIONS.ZIP / DEMOMENU.C < prev    next >
Text File  |  1990-05-20  |  13KB  |  315 lines

  1. /*------------------------- DEMOMENU.C -------------------------*/
  2. /*                                                              */
  3. /*  This file contains the VISIONS LIBRARY MENU DEMO software.  */
  4. /*                                                              */
  5. /*         Copyright 1990 Dan Vogel & David Bernazzani          */
  6. /*                                                              */
  7. /*   Date        Initials        Comments                       */
  8. /*                                                              */
  9. /*  03/07/90       DCV     Initial Release 0.00                 */
  10. /*--------------------------------------------------------------*/
  11.  
  12. #include <stdio.h>
  13. #include "USERLIST.H"
  14. #include "USERWIND.H"
  15. #include "USERMENU.H"
  16. #include "USERFORM.H"
  17. #include "DEMOPROT.H"
  18.  
  19. static char *cnotice="VISIONS Copyright 1990 Dan Vogel & David Bernazzani";
  20.  
  21. /*--------------------------------------------------------------*/
  22.  
  23.  
  24.  
  25. /*----------------------------------------------*/
  26. /*                Run_Menu                      */
  27. /* This is the menu library demonstration code. */
  28. /*----------------------------------------------*/
  29. int Run_Menu()
  30. {
  31.    WINDOW_HEAD *clear_window;      /* Window to clear screen. */
  32.    MENU_HEAD *new_menu;
  33.  
  34.    /*-------------------------------------------*/
  35.    /* Create a window just to clear the screen. */
  36.    /*-------------------------------------------*/
  37.    DefineWindow(&clear_window, 1, 1, 24, 80,
  38.       TEXT_BLACK, TEXT_WHITE, "", NOBORDER, FALSE, FALSE, TRUE);
  39.    DisplayWindow(clear_window);
  40.  
  41.    /*-------------------------------------------*/ 
  42.    /* Tell the user what this routine is about. */
  43.    /*-------------------------------------------*/
  44.    Menu_Intro();
  45.  
  46.    /*-------------------------------------------------*/
  47.    /* Allow user to select the desired demonstration. */
  48.    /*-------------------------------------------------*/
  49.    DefineMenu(&new_menu, 7,7,1,1,
  50.         SINGLEBORDER, HOT_EXEC_ON, TEXT_BLUE, TEXT_WHITE,
  51.         TEXT_WHITE, TEXT_BLUE, "SELECT MENU DEMONSTRATION");
  52.  
  53.    AddToMenu(new_menu, "Hot Key Demonstration", 'H', 0, *Menu_Hot);
  54.    AddToMenu(new_menu, "Auto-sizing of Menu", 'A', 0, *Menu_Auto);
  55.    AddToMenu(new_menu, "File Defined Menu", 'F', 0, *Menu_File);
  56.    AddToMenu(new_menu, "Exit Menu Demonstration", 'E', 1, NULL);
  57.  
  58.    /*---------------------------------*/
  59.    /* Get and execute user selection. */
  60.    /*---------------------------------*/
  61.    AutoDisplayMenu(new_menu);
  62.  
  63.    /*---------------------------------*/
  64.    /* And return menu memory to heap. */
  65.    /*---------------------------------*/
  66.    DeleteMenu(new_menu);
  67.  
  68.    RemoveWindow(clear_window);
  69.    DeleteWindow(clear_window);
  70.    return(0);
  71. }
  72.  
  73.  
  74.  
  75. /*---------------------------------------------------------------*/
  76. /*                         Menu_Hot                              */
  77. /* This routine demonstrates the difference between menus        */
  78. /* with hot key execution and without.  This is accomplished     */
  79. /* by showing the user two essentially identical menus, with     */
  80. /* and without the hot key execution feature enabled.  Actually  */
  81. /* executing a menu function, either by hot key, or by selecting */
  82. /* and hitting enter will display a dummy window to indicate     */
  83. /* which selection was made.                                     */
  84. /*---------------------------------------------------------------*/
  85. int Menu_Hot()
  86. {
  87.    MENU_HEAD *new_menu;
  88.  
  89.    /*-------------------------------------------*/
  90.    /* Allow user to see hot key execution       */
  91.    /* by creating a menu with hot keys enabled. */
  92.    /*-------------------------------------------*/
  93.    DefineMenu(&new_menu, 7,7,1,1,
  94.         SINGLEBORDER, HOT_EXEC_ON, TEXT_BLUE, TEXT_WHITE,
  95.         TEXT_WHITE, TEXT_BLUE, 
  96.         "Type 1, 2, or 3 to see Hot Key Execution");
  97.  
  98.    AddToMenu(new_menu, "1) Hot Key # 1", '1', 0, *Hot_1);
  99.    AddToMenu(new_menu, "2) Hot Key # 2", '2', 0, *Hot_2);
  100.    AddToMenu(new_menu, "3) Hot Key # 3", '3', 0, *Hot_3);
  101.  
  102.    /*---------------------------------*/
  103.    /* Get and execute user selection. */
  104.    /*---------------------------------*/
  105.    AutoDisplayMenu(new_menu);
  106.  
  107.    /*---------------------------------*/
  108.    /* And return menu memory to heap. */
  109.    /*---------------------------------*/
  110.    DeleteMenu(new_menu);
  111.  
  112.    /*----------------------------------------*/
  113.    /* Now define the exact same menu without */
  114.    /* hot key execution enabled, and an      */
  115.    /* appropriately different title.         */
  116.    /*----------------------------------------*/
  117.    DefineMenu(&new_menu, 7,7,1,1,
  118.         SINGLEBORDER, HOT_EXEC_OFF, TEXT_BLUE, TEXT_WHITE,
  119.         TEXT_WHITE, TEXT_BLUE,
  120.         "Type 1, 2, or 3 to see Hot Key Selection, then Enter to Execute");
  121.  
  122.    AddToMenu(new_menu, "1) Hot Key # 1", '1', 0, *Hot_1);
  123.    AddToMenu(new_menu, "2) Hot Key # 2", '2', 0, *Hot_2);
  124.    AddToMenu(new_menu, "3) Hot Key # 3", '3', 0, *Hot_3);
  125.  
  126.    /*---------------------------------*/
  127.    /* Get and execute user selection. */
  128.    /*---------------------------------*/
  129.    AutoDisplayMenu(new_menu);
  130.  
  131.    /*---------------------------------*/
  132.    /* And return menu memory to heap. */
  133.    /*---------------------------------*/
  134.    DeleteMenu(new_menu);
  135.  
  136.    return(0);
  137. }
  138.  
  139.  
  140.  
  141.  
  142. /*--------------------------------------------------------------*/
  143. /*                       Menu_Auto                              */
  144. /* This routine demonstrates the menu auto-sizing display       */
  145. /* capability.  This is accomplished by defining a menu         */
  146. /* size that is far too big for the actual size of the menu     */
  147. /* titles and selections.  This oversize menu is then displayed */
  148. /* using DisplayMenu.  After the user exits this menu, the      */
  149. /* same menu is redisplayed using AutoDisplayMenu, which scales */
  150. /* down the menu size to what is needed for the menu prompts    */
  151. /* and title.                                                   */
  152. /*--------------------------------------------------------------*/
  153. int Menu_Auto()
  154. {
  155.    MENU_HEAD *auto_menu;
  156.  
  157.    /*------------------*/
  158.    /* Define the menu. */
  159.    /*------------------*/
  160.    DefineMenu(&auto_menu, 5,5,19,70,
  161.         SINGLEBORDER, HOT_EXEC_ON, TEXT_BLUE, TEXT_WHITE,
  162.         TEXT_WHITE, TEXT_BLUE, "Menu Auto-Sizing Demonstration");
  163.  
  164.    AddToMenu(auto_menu, "Null selection", 'N', 0, NULL);
  165.    AddToMenu(auto_menu, "Display same menu with auto-sizing", 'D', 1, NULL);
  166.    AddToMenu(auto_menu, "Null selection", 'N', 0, NULL);
  167.    AddToMenu(auto_menu, "Null selection", 'N', 0, NULL);
  168.    AddToMenu(auto_menu, "Null selection", 'N', 0, NULL);
  169.  
  170.    /*---------------------------------------------*/
  171.    /* Show the user the menu without auto-sizing. */
  172.    /*---------------------------------------------*/
  173.    DisplayMenu(auto_menu);
  174.  
  175.    /*-----------------------*/
  176.    /* Now size it properly. */
  177.    /*-----------------------*/
  178.    AutoDisplayMenu(auto_menu);
  179.  
  180.    /*---------------------------------*/
  181.    /* And return menu memory to heap. */
  182.    /*---------------------------------*/
  183.    DeleteMenu(auto_menu);
  184.  
  185.    return(0);
  186. }
  187.  
  188.  
  189.  
  190.  
  191. /*----------------------------------------------------------------*/
  192. /*                        Menu_File                               */
  193. /* The following routine demonstrates the use of the              */
  194. /* DoFileMenu routine.  With this routine a user can execute      */
  195. /* a menu that is defined within a separate file.  This means     */
  196. /* that simple menu changes, like color, titles, and so, can      */
  197. /* be made to a file defined menu without recompiling any code.   */
  198. /* The drawback however is that a file defined menu can only      */
  199. /* return a non-zero value indicating the selection made from     */
  200. /* the menu, it can not execute a routine directly from the       */
  201. /* menu execution!  The format of the file is defined in the user */
  202. /* manual.  This should be referred to when modifying or creating */
  203. /* a file defined menu.  The file defined menu for this routine   */
  204. /* is FILEMENU.MNU.  The user should experiment with this file    */
  205. /* using the demonstration program to display it before creating  */
  206. /* a menu file from scratch.                                      */
  207. /*----------------------------------------------------------------*/
  208. int Menu_File()
  209. {
  210.    WINDOW_HEAD *file_window;
  211.    int val;
  212.    char buffer[81];
  213.  
  214.    /*------------------------------------------------------*/
  215.    /* Display a window to tell the user what is happening. */
  216.    /*------------------------------------------------------*/
  217.    DefineWindow(&file_window, 1, 1, 24, 80,
  218.         TEXT_BLUE, TEXT_WHITE, "VISIONS File Execution Demonstration",
  219.         SINGLEBORDER, FALSE, FALSE, TRUE);
  220.    DisplayWindow(file_window);
  221.    WindMesg(9,5,
  222.       "   The following menu is defined in the file FILEMENU.MNU. ");
  223.    WindMesg(24,28,"Hit any key to continue.");
  224.  
  225.    GetKey();    /* Force the user to strike a key. */
  226.  
  227.    val = DoFileMenu("FILEMENU.MNU");   /* Execute the file menu. */
  228.  
  229.    /*---------------------------------------*/
  230.    /* And tell the user the returned value. */
  231.    /*---------------------------------------*/
  232.    sprintf(buffer," The resulting value of the menu call was: %d",val);
  233.    WindMesgPtr(file_window,12,7,buffer);
  234.  
  235.    GetKey();    /* Force the user to strike a key. */
  236.  
  237.    RemoveWindow(file_window);
  238.    DeleteWindow(file_window);
  239.  
  240.    return(0);
  241. }
  242.  
  243.  
  244.  
  245. /*-----------------------------------------------*/
  246. /*                Menu_Intro                     */
  247. /* Introduce the user to this demonstration,     */
  248. /* explaining the purpose and what is happening. */
  249. /*-----------------------------------------------*/
  250. int Menu_Intro()
  251. {
  252.    WINDOW_HEAD *intro_window;
  253.  
  254.    DefineWindow(&intro_window, 1, 1, 24, 80,
  255.         TEXT_BLUE, TEXT_WHITE, "VISIONS Menu Demonstration Introduction",
  256.         SINGLEBORDER, FALSE, FALSE, TRUE);
  257.    DisplayWindow(intro_window);
  258.    WindMesg(8,5,"   The VISIONS menu library layers menu selection capability on top ");
  259.    WindMesg(9,5," of VISIONS windows.  As a result, VISIONS menus have all the color, ");
  260.    WindMesg(10,5," title, and border selections available from the window library.  In  ");
  261.    WindMesg(11,5," addition to these choices, the user may select hot key execution, ");
  262.    WindMesg(12,5," auto-sized menus, and file execution of menus.  Hot keys allow the  ");
  263.    WindMesg(13,5," menu user to select and execute a menu item with a single key.  Auto-");
  264.    WindMesg(14,5," sizing lets the programmer specify only the top left coordinate of the");
  265.    WindMesg(15,5," menu, VISIONS determines the height and width.  Finally, file definition");
  266.    WindMesg(16,5," of menus allows the user to specify the menu titles, coordinates, return");
  267.    WindMesg(17,5," values, and contents in a file.  This allows menu modification without");
  268.    WindMesg(18,5," recompiling.  File executed menus can not execute subroutines, but can");
  269.    WindMesg(19,5," return a selected value.  The source code used to create this ");
  270.    WindMesg(20,5," demonstration is supplied with the executable.");
  271.    WindMesg(24,28,"Hit any key to continue.");
  272.  
  273.    GetKey();
  274.  
  275.    RemoveWindow(intro_window);
  276.    DeleteWindow(intro_window);
  277.    return(0);
  278. }
  279.  
  280.  
  281.  
  282.  
  283. /*-------------------------------------------------------*/
  284. /*               Hot_1,  Hot_2,  Hot_3                   */
  285. /* The following routines simply display an error window */
  286. /* that indicates which routine is active.  These are    */
  287. /* used to tell the operator which menu selection has    */
  288. /* been activated for demonstration purposes.  More      */
  289. /* useful from a programmer's point of view is that      */
  290. /* these routines demonstrate the ErrWindow routine,     */
  291. /* which displays a single string of text centered on    */
  292. /* the screen and requires the user to strike a key      */
  293. /* before ErrWindow returns.  While this routine is      */
  294. /* not very flexible, it is a very quick way of          */
  295. /* displaying a short error message to the user!         */
  296. /*-------------------------------------------------------*/
  297. int Hot_1()
  298. {
  299.    ErrWindow("This is Hot Key routine # 1");
  300.    return(0);
  301. }
  302.  
  303. int Hot_2()
  304. {
  305.    ErrWindow("This is Hot Key routine # 2");
  306.    return(0);
  307. }
  308.  
  309. int Hot_3()
  310. {
  311.    ErrWindow("This is Hot Key routine # 3");
  312.    return(0);
  313. }
  314.  
  315.