home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************
- * CTEST.C *
- * *
- * Demonstrates use of the Microsoft Mouse from C 5.1 *
- * and QuickC. Creates a three-line menu. Either *
- * button selects the highlighted option. *
- * *
- * cmousem() is for medium model (QuickC default). *
- * For other memory models, replace cmousem() with the *
- * appropriate function... *
- * cmouses() - C small model *
- * cmousec() - C compact model *
- * cmousem() - C medium model *
- * cmousel() - C large or huge model *
- * *
- * Microsoft C 5.1: *
- * cl /AM ctest.c -link mouse *
- * *
- * QuickC: *
- * Program List.. CTEST.C, MOUSE.LIB *
- * *
- * NOTE: Program assumes mouse driver is installed. *
- **********************************************************/
-
- #include <stdio.h>
- #include <dos.h>
-
- void clearscreen();
- void writestring(char *, int, int, int);
- void cmousem(int *, int *, int *, int *);
-
- main()
- {
- int m1,m2,m3,m4;
- int menuptr;
- int wflag;
- int motion;
- int attr;
-
- /* Clear the display */
- clearscreen();
-
- /* Display simple instructions for user */
- writestring("CTEST - Mouse demonstration using C 5.1 or QuickC",1,1,7);
- writestring("Use mouse to highlight a menu option.",3,1,7);
- writestring("Press either button to select option. ",4,1,7);
-
- /* Check for mouse, resetting it in the process */
- m1 = 0;
- cmousem(&m1, &m2, &m3, &m4);
-
- /* Quit if mouse wasn't found */
- if (m1 == 0)
- {
- writestring("Error: Mouse not found ",4,1,7);
- exit(1);
- }
-
- /* Initialize menu pointer to first option */
- menuptr = 1;
-
- /* Initialize count of accumulated vertical mouse motion */
- motion = 0;
-
- /* Set flag to update menu first time */
- wflag = 1;
-
- /* Main loop starts here */
- while(1)
- {
-
- /* Update the menu only when necessary */
- if (wflag == 1)
- {
-
- /* Clear the update flag */
- wflag = 0;
-
- /* Print first line of the menu, highlighted if selected */
- if (menuptr == 1)
- attr = 0x70;
- else
- attr = 0x07;
- writestring(" 1. First menu option ",10,29,attr);
-
- /* Print second line of the menu, highlighted if selected */
- if (menuptr == 2)
- attr = 0x70;
- else
- attr = 0x07;
- writestring(" 2. Second option ",11,29,attr);
-
- /* Print third line of the menu, highlighted if selected */
- if (menuptr == 3)
- attr = 0x70;
- else
- attr = 0x07;
- writestring(" 3. Third option ",12,29,attr);
-
- /* Be sure highlighting is turned off */
- attr = 0x07;
-
- /* End of updating the menu */
- }
-
- /* Accumulate vertical mouse motion counts */
- m1 = 11;
- cmousem(&m1, &m2, &m3, &m4);
- motion = motion + m4;
-
- /* Move up the menu if enough mouse motion */
- if (motion < -17)
- {
- motion = 0;
- if (menuptr > 1)
- {
- menuptr--;
- wflag = 1;
- }
- }
-
- /* Move down the menu if enough mouse motion */
- if (motion > 17)
- {
- motion = 0;
- if (menuptr < 3)
- {
- menuptr++;
- wflag = 1;
- }
- }
-
- /* Check if left button pressed */
- m1 = 5;
- m2 = 0;
- cmousem(&m1, &m2, &m3, &m4);
- if (m2)
- {
- printf("\nLeft button used to select option %d\n", menuptr);
- exit(0);
- }
-
- /* Check if right button pressed */
- m1 = 5;
- m2 = 1;
- cmousem(&m1, &m2, &m3, &m4);
- if (m2)
- {
- printf("\nRight button used to select option %d\n", menuptr);
- exit(0);
- }
-
- /* Loop back until one of the buttons is pressed */
- }
- }
-
- void clearscreen()
- {
- union REGS reg;
-
- reg.x.ax = 0x600; /* Scroll up, clear whole window */
- reg.h.bh = 7; /* The normal attribute */
- reg.x.cx = 0; /* Rows and columns start at 0 */
- reg.x.dx = 0x184f; /* Rows 0 to 24, columns 0 to 79 */
-
- int86(0x10, ®, ®);
- }
-
- void writestring(str, row, col, attr)
- char str[];
- int row, col, attr;
- {
- int i;
- union REGS reg;
-
- for (i=0; str[i]; i++)
- {
-
- reg.h.ah = 2; /* Set cursor position */
- reg.h.bh = 0; /* Page 0 */
- reg.h.dh = row - 1; /* Row, in range 0 to 24 */
- reg.h.dl = (col++) - 1; /* Column, in range 0 to 79 */
- int86(0x10, ®, ®); /* Video interrupt */
-
- reg.h.ah = 9; /* Write a character with attribute */
- reg.h.al = str[i]; /* Character */
- reg.x.bx = attr; /* Page 0, attribute byte */
- reg.x.cx = 1; /* Count of characters to write */
- int86(0x10, ®, ®);
- }
- }
-