home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************
-
- MOUS_LIB.C
-
- Demonstrates the most commonly used function calls in
- programming the Microsoft mouse driver. This was written
- on Microsoft C 5.1 using the small model. All the calls
- made to the driver are made using cmouses, the small-model
- library included in MOUSE.LIB.
-
- Written by David Tryon
- Microsoft Product Support
- 6/14/88
-
- To build, type: cl /AS mous_lib.c -link mouse
-
- NOTE: Program assumes mouse and mouse driver are installed.
- *******************************************************************/
-
- #include <graph.h>
- #include <dos.h>
- #define MOUSE 0x33
-
- main ()
- {
- void chkdrv (); /* Checks if driver installed */
- unsigned short cursor [32]; /* Array to contain cursor */
- unsigned short m1, m2, m3, m4;
- unsigned short *cursor_array;
-
- chkdrv (); /* Exit if no driver loaded */
-
- _setvideomode (_ERESCOLOR); /* Set graphics mode
- (For CGA, use _HRESBW) */
-
- /* Function 0: Mouse Reset and Status */
- m1 = 0;
- cmouses ( &m1, &m2, &m3, &m4);
-
- /* Define screen mask */
-
- cursor [0] = 0xE1FF;
- cursor [1] = 0xE1FF;
- cursor [2] = 0xE1FF;
- cursor [3] = 0xE1FF;
- cursor [4] = 0xE1FF;
- cursor [5] = 0xE000;
- cursor [6] = 0xE000;
- cursor [7] = 0xE000;
- cursor [8] = 0x0000;
- cursor [9] = 0x0000;
- cursor [10] = 0x0000;
- cursor [11] = 0x0000;
- cursor [12] = 0x0000;
- cursor [13] = 0x0000;
- cursor [14] = 0x0000;
- cursor [15] = 0x0000;
-
- /* Define cursor mask */
-
- cursor [16] = 0x1E00;
- cursor [17] = 0x1200;
- cursor [18] = 0x1200;
- cursor [19] = 0x1200;
- cursor [20] = 0x1200;
- cursor [21] = 0x13FF;
- cursor [22] = 0x1249;
- cursor [23] = 0x1249;
- cursor [24] = 0xF249;
- cursor [25] = 0x9001;
- cursor [26] = 0x9001;
- cursor [27] = 0x9001;
- cursor [28] = 0x8001;
- cursor [29] = 0x8001;
- cursor [30] = 0x8001;
- cursor [31] = 0xFFFF;
-
- *cursor_array = (unsigned short) cursor;
-
- /* Function 9: Set Graphics Cursor Block */
- m1 = 9;
- m2 = 5;
- m3 = 0;
- cmouses ( &m1, &m2, &m3, cursor_array );
-
- /* Function 7: Set Horizontal Limits */
- m1 = 7;
- m3 = 100;
- m4 = 540;
- cmouses ( &m1, &m2, &m3, &m4);
-
- /* Function 8: Set Vertical Limits */
- m1 = 8;
- m3 = 50;
- m4 = 300;
- cmouses ( &m1, &m2, &m3, &m4);
-
- /* Draw box showing mouse limits */
- _setcolor (9);
- _moveto (100, 50);
- _lineto (540, 50);
- _lineto (540,300);
- _lineto (100,300);
- _lineto (100, 50);
-
- /* Function 1: Show Cursor */
- m1 = 1;
- cmouses ( &m1, &m2, &m3, &m4);
-
- /* Function 3: Get Button Status and Mouse Position */
- do
- {
- m1 = 3;
- cmouses ( &m1, &m2, &m3, &m4);
- _settextposition (1,1);
- printf ("%d \t%d ", m3, m4);
- } while (!m2); /* Loop until button pressed */
-
- /* Function 2: Hide Cursor */
- m1 = 2;
- cmouses ( &m1, &m2, &m3, &m4);
-
- _setvideomode (_DEFAULTMODE); /* Return to original mode */
- }
-
-
- void chkdrv ()
- {
- union REGS inregs, outregs;
- struct SREGS segregs;
- unsigned long address;
- unsigned char first_byte;
-
- inregs.x.ax = 0x3533; /* Get interrupt vector for 0x33 */
- intdosx ( &inregs, &outregs, &segregs);
- address = (((long) segregs.es) << 16) + (long) outregs.x.bx ;
- first_byte = (unsigned char) * (long far *) address;
-
- /* Be sure vector isn't 0 and first instruction isn't iret */
- if ((address == 0L) || (first_byte == 0xCF))
- {
- printf ("\nThe Mouse Driver must be installed to use this program");
- exit ();
- }
- }
-