home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / MOUSE / MSMOUSE1.ZIP / C&QC.ZIP / MOUS_LIB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-10  |  3.9 KB  |  146 lines

  1. /*******************************************************************
  2.  
  3.    MOUS_LIB.C
  4.  
  5.       Demonstrates the most commonly used function calls in
  6.    programming the Microsoft mouse driver. This was written
  7.    on Microsoft C 5.1 using the small model. All the calls
  8.    made to the driver are made using cmouses, the small-model
  9.    library included in MOUSE.LIB.
  10.  
  11.    Written by David Tryon
  12.    Microsoft Product Support
  13.    6/14/88
  14.  
  15.    To build, type:  cl /AS mous_lib.c -link mouse
  16.  
  17.    NOTE: Program assumes mouse and mouse driver are installed.
  18. *******************************************************************/
  19.  
  20. #include <graph.h>
  21. #include <dos.h>
  22. #define MOUSE 0x33
  23.  
  24. main ()
  25. {
  26.     void chkdrv ();                  /*  Checks if driver installed */
  27.     unsigned short cursor [32];      /*  Array to contain cursor    */
  28.     unsigned short m1, m2, m3, m4;
  29.     unsigned short *cursor_array;
  30.  
  31.     chkdrv ();                       /*  Exit if no driver loaded   */
  32.  
  33.     _setvideomode (_ERESCOLOR);      /*  Set graphics mode
  34.                                           (For CGA, use _HRESBW)    */
  35.  
  36.     /*   Function 0:  Mouse Reset and Status  */
  37.     m1 = 0;
  38.     cmouses ( &m1, &m2, &m3, &m4);
  39.  
  40.     /*  Define screen mask  */
  41.  
  42.     cursor [0]  = 0xE1FF;
  43.     cursor [1]  = 0xE1FF;
  44.     cursor [2]  = 0xE1FF;
  45.     cursor [3]  = 0xE1FF;
  46.     cursor [4]  = 0xE1FF;
  47.     cursor [5]  = 0xE000;
  48.     cursor [6]  = 0xE000;
  49.     cursor [7]  = 0xE000;
  50.     cursor [8]  = 0x0000;
  51.     cursor [9]  = 0x0000;
  52.     cursor [10] = 0x0000;
  53.     cursor [11] = 0x0000;
  54.     cursor [12] = 0x0000;
  55.     cursor [13] = 0x0000;
  56.     cursor [14] = 0x0000;
  57.     cursor [15] = 0x0000;
  58.  
  59.     /*  Define cursor mask  */
  60.  
  61.     cursor [16] = 0x1E00;
  62.     cursor [17] = 0x1200;
  63.     cursor [18] = 0x1200;
  64.     cursor [19] = 0x1200;
  65.     cursor [20] = 0x1200;
  66.     cursor [21] = 0x13FF;
  67.     cursor [22] = 0x1249;
  68.     cursor [23] = 0x1249;
  69.     cursor [24] = 0xF249;
  70.     cursor [25] = 0x9001;
  71.     cursor [26] = 0x9001;
  72.     cursor [27] = 0x9001;
  73.     cursor [28] = 0x8001;
  74.     cursor [29] = 0x8001;
  75.     cursor [30] = 0x8001;
  76.     cursor [31] = 0xFFFF;
  77.  
  78.     *cursor_array = (unsigned short) cursor;
  79.  
  80.     /*   Function 9:  Set Graphics Cursor Block  */
  81.     m1 = 9;
  82.     m2 = 5;
  83.     m3 = 0;
  84.     cmouses ( &m1, &m2, &m3, cursor_array );
  85.  
  86.     /*   Function 7:  Set Horizontal Limits  */
  87.     m1 = 7;
  88.     m3 = 100;
  89.     m4 = 540;
  90.     cmouses ( &m1, &m2, &m3, &m4);
  91.  
  92.     /*   Function 8:  Set Vertical Limits   */
  93.     m1 = 8;
  94.     m3 = 50;
  95.     m4 = 300;
  96.     cmouses ( &m1, &m2, &m3, &m4);
  97.  
  98.     /*  Draw box showing mouse limits  */
  99.     _setcolor (9);
  100.     _moveto (100, 50);
  101.     _lineto (540, 50);
  102.     _lineto (540,300);
  103.     _lineto (100,300);
  104.     _lineto (100, 50);
  105.  
  106.     /*   Function 1:  Show Cursor        */
  107.     m1 = 1;
  108.     cmouses ( &m1, &m2, &m3, &m4);
  109.  
  110.     /*   Function 3:  Get Button Status and Mouse Position   */
  111.     do
  112.     {
  113.         m1 = 3;
  114.         cmouses ( &m1, &m2, &m3, &m4);
  115.         _settextposition (1,1);
  116.         printf ("%d  \t%d     ", m3, m4);
  117.     } while (!m2);                   /*  Loop until button pressed  */
  118.  
  119.     /*  Function 2:  Hide Cursor         */
  120.     m1 = 2;
  121.     cmouses ( &m1, &m2, &m3, &m4);
  122.  
  123.     _setvideomode (_DEFAULTMODE);    /*  Return to original mode  */
  124. }
  125.  
  126.  
  127. void chkdrv ()
  128. {
  129.     union REGS inregs, outregs;
  130.     struct SREGS segregs;
  131.     unsigned long address;
  132.     unsigned char first_byte;
  133.  
  134.     inregs.x.ax = 0x3533;            /* Get interrupt vector for 0x33 */
  135.     intdosx ( &inregs, &outregs, &segregs);
  136.     address = (((long) segregs.es) << 16) + (long) outregs.x.bx ;
  137.     first_byte = (unsigned char) * (long far *) address;
  138.  
  139.     /* Be sure vector isn't 0 and first instruction isn't iret */
  140.     if ((address == 0L) || (first_byte == 0xCF))
  141.     {
  142.         printf ("\nThe Mouse Driver must be installed to use this program");
  143.         exit ();
  144.     }
  145. }
  146.