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

  1. /****************************************************************
  2. *
  3. *  Name:          EXAMPLES
  4. *
  5. *  Function:      Display a menu listing the example programs and
  6. *                 start an example as a new process when so requested.
  7. *
  8. *  Shows how to:  1. read a DESQview Program Information File (DVP)
  9. *                    from disk. 
  10. *                 2. adjust the DVP to reflect the current drive and 
  11. *                    directory.
  12. *                 3. start a new process using the DVP.
  13. *
  14. ****************************************************************/
  15.  
  16. #include <stdio.h>
  17. #include "dvapi.h"
  18.  
  19. /* minimum API version required and actual version */
  20. #define required 0x201
  21. int  version;
  22.  
  23. /* object handles */
  24. ulong win,kbd,apphan;
  25.  
  26. /* variables used when reading the menu */
  27. char *kbuf,field;
  28. int   klng;
  29.  
  30. /* file variables */
  31. FILE *f1,*fopen();
  32.  
  33. /* buffers for the DVP and for the current directory path */
  34. char dvpbuf[416];
  35. char pathbuf[64];
  36.  
  37. /* error messages */
  38. char error1[] = " Can't find .DVP file ";
  39. int  lerror1  = sizeof(error1)-1;
  40. char error2[] = " Error loading .DVP file ";
  41. int  lerror2  = sizeof(error2)-1;
  42.  
  43. /* DVP file names for each menu entry */
  44. char *pif_names[] = {"hello.dvp",
  45.                      "fruit.dvp",
  46.                      "point.dvp",
  47.                      "washer.dvp",
  48.                      "snakes.dvp",
  49.                      "server.dvp",
  50.                      "request.dvp"};
  51.  
  52. /* menu contents */
  53. char menu1[] = "\
  54.                 \
  55.  Hello       HE \
  56.  Fruit       FR \
  57.  Point       PT \
  58.  Washer      WA \
  59.  Snakes      SN \
  60.  Server      SV \
  61.  Request     RQ ";
  62.  
  63.  
  64. /* menu field table */
  65. char ftab1[] = {ftab(9,FTH_KEYSELECT+FTH_MODIFIED,0,0,9,1),
  66.                      0,8,0,8,FTE_OUTPUT,0,0,0,
  67.                      1,0,1,15,FTE_SELECT,'H',1,'E',
  68.                      2,0,2,15,FTE_SELECT,'F',1,'R',
  69.                      3,0,3,15,FTE_SELECT,'P',1,'T',
  70.                      4,0,4,15,FTE_SELECT,'W',1,'A',
  71.                      5,0,5,15,FTE_SELECT,'S',1,'N',
  72.                      6,0,6,15,FTE_SELECT,'S',1,'V',
  73.                      7,0,7,15,FTE_SELECT,'R',1,'Q',
  74.                      1,0,0,0,FTE_SELECT,27,1,0, /* Esc - invisible field */
  75.                      };
  76.  
  77.  
  78. /**********************************************************************
  79. *  main  -  check for DESQview present and enable required extensions.
  80. ***********************************************************************/
  81.  
  82. main () {
  83.   /* initialize C interfaces and get API version number */
  84.   version = api_init();
  85.  
  86.   /* if DESQview is not running or version is too low, display a message */ 
  87.   if (version < required) {
  88.     printf ("This program requires DESQview version %d.02%d or later.\n",
  89.              required/256,required%256);
  90.     }
  91.  
  92.   /* tell DESQview what extensions to enable and start application */
  93.   else {
  94.     api_level (required);
  95.     program_body();
  96.     }
  97.  
  98.   /* disable C interfaces and return from program */
  99.   api_exit();
  100.   }
  101.  
  102.  
  103. /**********************************************************************
  104. *  program_body  -  display list of examples and start then when selected.
  105. ***********************************************************************/
  106.  
  107. program_body () {
  108.   /* get default object handles */
  109.   win = win_me();
  110.   kbd = key_me();
  111.  
  112.   /* resize the physical and logical window */
  113.   win_resize (win,8,16);
  114.   win_lsize (win,8,16); 
  115.  
  116.   /* position the window and set to use logical attributes */
  117.   win_origin (win,0,0);
  118.   win_move (win,1,63);
  119.   win_logattr (win,1);
  120.   win_attr (win,1);
  121.  
  122.   /* turn on field mode, turn off hardware cursor */
  123.   key_subfrom (kbd,KBF_CURSOR);
  124.   key_addto (kbd,KBF_FIELD);
  125.  
  126.   /* write contents and field table to the menu and display it */
  127.   win_swrite (win,menu1);
  128.   win_stream (win,ftab1);
  129.   win_redraw (win);
  130.  
  131.   /* loop until the window is closed */
  132.   while (1) {
  133.  
  134.     /* wait for menu selection, determine field #, and deselect it */
  135.     key_read (kbd,&kbuf,&klng); 
  136.     field = *kbuf; 
  137.     fld_reset (win); 
  138.  
  139.     /* exit if field 9 (ESC) selected */
  140.     if (field == 9) break;
  141.  
  142.     /* open DVP file and display error message if necessary */
  143.     f1 = fopen(pif_names[field-2],"rb");
  144.     if (f1 == NULL) {
  145.       win_disperor (win,error1,lerror1,1,lerror1,1,0);
  146.       continue;
  147.       }
  148.  
  149.     /* read DVP file and display error message if necessary */
  150.     if (fread (dvpbuf,416,1,f1) != 1) {
  151.       win_disperor (win,error2,lerror2,1,lerror2,1,0);
  152.       continue;
  153.       }
  154.  
  155.     /* close the DVP file and get current directory */
  156.     fclose (f1);
  157.     if (getcwd (pathbuf,64) == NULL) break;
  158.  
  159.     /* set drive letter and data path fields in the DVP */
  160.     dvpbuf[100] = pathbuf[0];
  161.     strcpy (&dvpbuf[101],&pathbuf[2]);
  162.  
  163.     /* start the application and loop */
  164.     apphan = app_start(dvpbuf,416);
  165.     }
  166.   }
  167.