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

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