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

  1. /**********************************************************
  2. *  MSCEXAMP.C                                             *
  3. *                                                         *
  4. *  Demonstrates use of the Microsoft Mouse from C 5.1     *
  5. *  and QuickC. It checks to see that the mouse driver was *
  6. *  installed, displays a graphics mode cursor, and limits *
  7. *  mouse cursor motion to the middle of the screen.       *
  8. *                                                         *
  9. *  cmousem() is for medium memory model (QuickC default). *
  10. *  For other memory models, replace cmousem() with the    *
  11. *  appropriate function:                                  *
  12. *     cmouses() - C small model                           *
  13. *     cmousec() - C compact model                         *
  14. *     cmousem() - C medium model                          *
  15. *     cmousel() - C large or huge model                   *
  16. *                                                         *
  17. *  Microsoft C 5.1:                                       *
  18. *     cl /AM mscexamp.c -link mouse                       *
  19. *                                                         *
  20. *  QuickC:                                                *
  21. *     Program List MSCEXAMP.C, MOUSE.LIB                  *
  22. **********************************************************/
  23.  
  24. #include <stdio.h>
  25. #include <dos.h>
  26. #include <graph.h>
  27.  
  28. void chkdrv();
  29.  
  30. main()
  31. {
  32.     int m1, m2, m3, m4;
  33.  
  34.     chkdrv();                /* Check for mouse driver   */
  35.  
  36.     m1 = 0;                  /* Initialize mouse         */
  37.     cmousem( &m1, &m2, &m3, &m4);
  38.  
  39.     if ( m1 == 0 )
  40.         {
  41.         printf("Microsoft Mouse NOT found");
  42.         exit (-1);           /* Exit, if mouse not found */
  43.         }
  44.  
  45.     _setvideomode(_HRESBW);
  46.  
  47.     m1 = 4;                  /* Function call 4          */
  48.     m3 = 200;                /* Set mouse position at    */
  49.     m4 = 100;                /* center of the screen     */
  50.     cmousem( &m1, &m2, &m3, &m4);
  51.  
  52.     m1 = 7;                  /* Function call 7          */
  53.     m3 = 150;                /* minimum horizontal value */
  54.     m4 = 450;                /* maximum horizontal value */
  55.     cmousem( &m1, &m2, &m3, &m4);
  56.  
  57.     m1 = 8;                  /* Function call 8          */
  58.     m3 = 50;                 /* minimum vertical value   */
  59.     m4 = 150;                /* maximum vertical value   */
  60.     cmousem( &m1, &m2, &m3, &m4);
  61.  
  62.     printf("Graphics cursor limited to center of the screen.\n");
  63.     printf("Press the left button to EXIT.");
  64.  
  65.     m1 = 1;                  /* Function 1, Show Cursor  */
  66.     cmousem( &m1, &m2, &m3, &m4);
  67.  
  68.     m2 = 0;                  /* Loop until left mouse    */
  69.     while ( m2 != 1 )        /* button is pressed        */
  70.         {
  71.         m1 = 3;
  72.         cmousem( &m1, &m2, &m3, &m4 );
  73.         }
  74.  
  75.     m1 = 2;                  /* Function 2, hide cursor  */
  76.     cmousem( &m1, &m2, &m3, &m4);
  77.  
  78.     _setvideomode(_DEFAULTMODE);
  79. }
  80.  
  81. void chkdrv ()
  82. {
  83.     unsigned long address;
  84.     unsigned char first_byte;
  85.  
  86.     union REGS inregs, outregs;    /*  Structures to contain      */
  87.     struct SREGS segregs;          /*  register values for intdosx */
  88.  
  89.     inregs.x.ax = 0x3533;          /* Get interrupt vector for 0x33 */
  90.     intdosx ( &inregs, &outregs, &segregs);
  91.     address = (((long) segregs.es) << 16) + (long) outregs.x.bx ;
  92.     first_byte = (unsigned char) * (long far *) address;
  93.  
  94.     /* Be sure vector isn't 0 and first instruction isn't iret */
  95.     if ((address == 0L) || (first_byte == 0xCF))
  96.     {
  97.         printf ("\nThe Mouse Driver must be installed to use this program");
  98.         exit ();
  99.     }
  100. }
  101.