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

  1. /**********************************************************
  2. *  CTEST.C                                                *
  3. *                                                         *
  4. *  Demonstrates use of the Microsoft Mouse from C 5.1     *
  5. *  and QuickC.  Creates a three-line menu.  Either        *
  6. *  button selects the highlighted option.                 *
  7. *                                                         *
  8. *  cmousem() is for medium model (QuickC default).        *
  9. *  For other memory models, replace cmousem() with the    *
  10. *  appropriate function...                                *
  11. *     cmouses() - C small model                           *
  12. *     cmousec() - C compact model                         *
  13. *     cmousem() - C medium model                          *
  14. *     cmousel() - C large or huge model                   *
  15. *                                                         *
  16. *  Microsoft C 5.1:                                       *
  17. *     cl /AM ctest.c -link mouse                          *
  18. *                                                         *
  19. *  QuickC:                                                *
  20. *     Program List.. CTEST.C, MOUSE.LIB                   *
  21. *                                                         *
  22. *  NOTE: Program assumes mouse driver is installed.       *
  23. **********************************************************/
  24.  
  25. #include <stdio.h>
  26. #include <dos.h>
  27.  
  28. void clearscreen();
  29. void writestring(char *, int, int, int);
  30. void cmousem(int *, int *, int *, int *);
  31.  
  32. main()
  33. {
  34.     int m1,m2,m3,m4;
  35.     int menuptr;
  36.     int wflag;
  37.     int motion;
  38.     int attr;
  39.  
  40.     /* Clear the display */
  41.     clearscreen();
  42.  
  43.     /* Display simple instructions for user */
  44.     writestring("CTEST - Mouse demonstration using C 5.1 or QuickC",1,1,7);
  45.     writestring("Use mouse to highlight a menu option.",3,1,7);
  46.     writestring("Press either button to select option. ",4,1,7);
  47.  
  48.     /* Check for mouse, resetting it in the process */
  49.     m1 = 0;
  50.     cmousem(&m1, &m2, &m3, &m4);
  51.  
  52.     /* Quit if mouse wasn't found */
  53.     if (m1 == 0)
  54.         {
  55.         writestring("Error: Mouse not found ",4,1,7);
  56.         exit(1);
  57.         }
  58.  
  59.     /* Initialize menu pointer to first option */
  60.     menuptr = 1;
  61.  
  62.     /* Initialize count of accumulated vertical mouse motion */
  63.     motion = 0;
  64.  
  65.     /* Set flag to update menu first time */
  66.     wflag = 1;
  67.  
  68.     /* Main loop starts here */
  69.     while(1)
  70.         {
  71.  
  72.         /* Update the menu only when necessary */
  73.         if (wflag == 1)
  74.             {
  75.  
  76.             /* Clear the update flag */
  77.             wflag = 0;
  78.  
  79.             /* Print first line of the menu, highlighted if selected */
  80.             if (menuptr == 1)
  81.                 attr = 0x70;
  82.             else
  83.                 attr = 0x07;
  84.             writestring(" 1. First menu option ",10,29,attr);
  85.  
  86.             /* Print second line of the menu, highlighted if selected */
  87.             if (menuptr == 2)
  88.                 attr = 0x70;
  89.             else
  90.                 attr = 0x07;
  91.             writestring(" 2. Second option     ",11,29,attr);
  92.  
  93.             /* Print third line of the menu, highlighted if selected */
  94.             if (menuptr == 3)
  95.                 attr = 0x70;
  96.             else
  97.                 attr = 0x07;
  98.             writestring(" 3. Third option      ",12,29,attr);
  99.  
  100.             /* Be sure highlighting is turned off */
  101.             attr = 0x07;
  102.  
  103.             /* End of updating the menu */
  104.             }
  105.  
  106.         /* Accumulate vertical mouse motion counts */
  107.         m1 = 11;
  108.         cmousem(&m1, &m2, &m3, &m4);
  109.         motion = motion + m4;
  110.  
  111.         /* Move up the menu if enough mouse motion */
  112.         if (motion < -17)
  113.             {
  114.             motion = 0;
  115.             if (menuptr > 1)
  116.                 {
  117.                 menuptr--;
  118.                 wflag = 1;
  119.                 }
  120.             }
  121.  
  122.         /* Move down the menu if enough mouse motion */
  123.         if (motion > 17)
  124.             {
  125.             motion = 0;
  126.             if (menuptr < 3)
  127.                 {
  128.                 menuptr++;
  129.                 wflag = 1;
  130.                 }
  131.             }
  132.  
  133.         /* Check if left button pressed */
  134.         m1 = 5;
  135.         m2 = 0;
  136.         cmousem(&m1, &m2, &m3, &m4);
  137.         if (m2)
  138.             {
  139.             printf("\nLeft button used to select option %d\n", menuptr);
  140.             exit(0);
  141.             }
  142.  
  143.         /* Check if right button pressed */
  144.         m1 = 5;
  145.         m2 = 1;
  146.         cmousem(&m1, &m2, &m3, &m4);
  147.         if (m2)
  148.             {
  149.             printf("\nRight button used to select option %d\n", menuptr);
  150.             exit(0);
  151.             }
  152.  
  153.         /* Loop back until one of the buttons is pressed */
  154.         }
  155. }
  156.  
  157. void clearscreen()
  158. {
  159.     union REGS reg;
  160.  
  161.     reg.x.ax = 0x600;    /* Scroll up, clear whole window */
  162.     reg.h.bh = 7;        /* The normal attribute */
  163.     reg.x.cx = 0;        /* Rows and columns start at 0 */
  164.     reg.x.dx = 0x184f;   /* Rows 0 to 24, columns 0 to 79 */
  165.  
  166.     int86(0x10, ®, ®);
  167. }
  168.  
  169. void writestring(str, row, col, attr)
  170. char str[];
  171. int row, col, attr;
  172. {
  173.     int i;
  174.     union REGS reg;
  175.  
  176.     for (i=0; str[i]; i++)
  177.         {
  178.  
  179.         reg.h.ah = 2;             /* Set cursor position */
  180.         reg.h.bh = 0;             /* Page 0 */
  181.         reg.h.dh = row - 1;       /* Row, in range 0 to 24 */
  182.         reg.h.dl = (col++) - 1;   /* Column, in range 0 to 79 */
  183.         int86(0x10, ®, ®);  /* Video interrupt */
  184.  
  185.         reg.h.ah = 9;             /* Write a character with attribute */
  186.         reg.h.al = str[i];        /* Character */
  187.         reg.x.bx = attr;          /* Page 0, attribute byte */
  188.         reg.x.cx = 1;             /* Count of characters to write */
  189.         int86(0x10, ®, ®);
  190.         }
  191. }
  192.