home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / desqview / api_exam.arc / FRUIT.C < prev    next >
Text File  |  1988-04-28  |  4KB  |  133 lines

  1. /****************************************************************
  2. *
  3. *  Name:          FRUIT
  4. *
  5. *  Function:      display a pop-up menu and report selections
  6. *
  7. *  Shows how to:  1. create a new window and associated keyboard.
  8. *                 2. define the contents and fields for a menu.
  9. *                 3. move and display a window.
  10. *                 4. take input from a menu.
  11. *
  12. ****************************************************************/
  13.  
  14. #include <stdio.h>
  15. #include "dvapi.h"
  16.  
  17. /* minimum API version required and actual API version */
  18. #define required 0x201
  19. int  version;
  20.  
  21. /* object handles */
  22. ulong win,kbd;
  23.  
  24. /* variables used when reading the menu keyboard */
  25. char *kbuf,field;
  26. int   klng;
  27.  
  28. /* this string defines the contents of the menu */
  29. char menu1[] = "\
  30.  apples   A \
  31.  bananas  B \
  32.  oranges  O \
  33.  pears    P ";
  34.  
  35. /* this string defines the field table for the menu.  Note that the 
  36.    ftab macro is used to define the field table header.  This macro,
  37.    defined in dvapi.h, automatically prefixes the field table with a 
  38.    window stream so that the resulting string can be sent via a
  39.    win_stream call.  Following the header is a field table entry for
  40.    each field in the menu.
  41. */
  42. char ftab1[] = {ftab(5,FTH_KEYSELECT+FTH_MODIFIED,0,0,9,1),
  43.                      0,0,0,11,FTE_SELECT,'A',1,0,
  44.                      1,0,1,11,FTE_SELECT,'B',1,0,
  45.                      2,0,2,11,FTE_SELECT,'O',1,0,
  46.                      3,0,3,11,FTE_SELECT,'P',1,0,
  47.                      1,0,0,0,FTE_SELECT,27,1,0, /* Esc - invisible field */
  48.                      };
  49.  
  50.  
  51. /**********************************************************************
  52. *  main  -  check for DESQview present and enable required extensions.
  53. ***********************************************************************/
  54.  
  55. main () {
  56.   /* initialize C interfaces and get API version number */
  57.   version = api_init();
  58.  
  59.   /* if DESQview is not running or version is too low, display a message */ 
  60.   if (version < required) {
  61.     printf ("This program requires DESQview version %d.02%d or later.\n",
  62.              required/256,required%256);
  63.     }
  64.  
  65.   /* tell DESQview what extensions to enable and start application */
  66.   else {
  67.     api_level (required);
  68.     program_body();
  69.     }
  70.  
  71.   /* disable C interfaces and return from program */
  72.   api_exit();
  73.   }
  74.  
  75.  
  76. /**********************************************************************
  77. *  program_body  -  build menu and display message when item is selected.
  78. ***********************************************************************/
  79.  
  80. program_body () {
  81.  
  82.   /* create the menu window and set it to use logical attributes */
  83.   win = win_new ("fruit",5,4,12);
  84.   win_logattr (win,1);
  85.   win_attr (win,1);
  86.  
  87.   /* create a keyboard object for the menu and open it in field mode */
  88.   kbd = key_new();
  89.   key_open  (kbd,win);
  90.   key_addto (kbd,KBF_FIELD);
  91.  
  92.   /* write the contents and field table to the menu window */
  93.   win_swrite (win,menu1);
  94.   win_stream (win,ftab1);
  95.  
  96.   /* reposition and display the menu */
  97.   win_move (win,9,33);
  98.   win_unhide (win);
  99.   win_top (win);
  100.  
  101.   /* loop until field 5 is selected */
  102.   field = 0;
  103.   while (field != 5) {
  104.  
  105.     /* wait for a field to be selected, reset it, and display a message */
  106.     key_read (kbd,&kbuf,&klng);
  107.     field = *kbuf;
  108.     fld_reset (win);
  109.     win_printf (win_me(),"field %d selected\n",field);
  110.     }
  111.  
  112.   /* free created objects */
  113.   key_free (kbd);
  114.   win_free (win);
  115.   }
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.