home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / desqview / api_exam.arc / POINT.C < prev    next >
C/C++ Source or Header  |  1988-04-28  |  3KB  |  133 lines

  1. /****************************************************************
  2. *
  3. *  Name:          POINT
  4. *
  5. *  Function:      track the pointer as it passes through the window.
  6. *
  7. *  Shows how to:  1. create and read a pointer object.
  8. *                 2. force the keyboard mouse ON, if applicable.
  9. *                 3. display single characters in a window.
  10. *                 4. jump the pointer.
  11. *                 5. change cursor position for a window.
  12. *
  13. ****************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include "dvapi.h"
  17.  
  18. /* minimum API version required */
  19. #define required 0x201
  20.  
  21. /* actual API version number */
  22. int    version;
  23.  
  24. /* object handles */
  25. ulong  win,ptr;
  26.  
  27. /* variables used to read pointer messages */
  28.  
  29. int     mlng;
  30. struct {int  row;
  31.         int  col;
  32.         char button;
  33.         char field;
  34.        } *mptr;
  35.  
  36. /* startup message */
  37. char   msg1[] = "\
  38. This program will display a \"0\" wherever you\n\
  39. move the mouse and a \"1\" wherever you click\n\
  40. button 1.  Button 2 exits the program.\n";
  41.  
  42.  
  43. /**********************************************************************
  44. *  main  -  check for DESQview present and enable required extensions.
  45. ***********************************************************************/
  46.  
  47. main () {
  48.   /* initialize C interfaces and get API version number */
  49.   version = api_init();
  50.  
  51.   /* if DESQview is not running or version is too low, display a message */ 
  52.   if (version < required) {
  53.     printf ("This program requires DESQview version %d.02%d or later.\n",
  54.              required/256,required%256);
  55.     }
  56.  
  57.   /* tell DESQview what extensions to enable and start application */
  58.   else {
  59.     api_level (required);
  60.     program_body();
  61.     }
  62.  
  63.   /* disable C interfaces and return from program */
  64.   api_exit();
  65.   }
  66.  
  67.  
  68. /**********************************************************************
  69. *  program_body  -  display a "0" wherever the pointer moves and a
  70. *                   "1" wherever button 1 is clicked.
  71. ***********************************************************************/
  72.  
  73. program_body () {
  74.   /* find window handle and create a pointer object */
  75.   win = win_me();
  76.   ptr = ptr_new();
  77.  
  78.   /* erase the window and display startup message */
  79.   win_erase (win);
  80.   win_swrite (win,msg1);
  81.  
  82.   /* open the pointer object, force keyboard mouse ON, and position pointer */
  83.   ptr_open (ptr,win);
  84.   api_kmouse (1);
  85.   ptr_write (ptr,4,20);
  86.  
  87.   /* loop until button 2 is clicked */
  88.   do {
  89.  
  90.     /* read a pointer message and extract button number */
  91.     ptr_read (ptr,&mptr,&mlng);
  92.  
  93.     /* move cursor to pointer position and display button # or 0 */
  94.     win_cursor (win,mptr->row,mptr->col);
  95.     win_putc (win,'0'+(mptr->button),7);
  96.     } 
  97.     while ((mptr->button) != 2);
  98.  
  99.   /* free pointer object and return */
  100.   ptr_free (ptr);
  101.   }
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.