1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
   | /* Demonstrates the most basic mouse function */
#include <conio.h>
#include <stdio.h>
#include <dos.h>// prototypes 
int initialize_mouse(); 
void reset_mouse (); 
void show_mouse_pointer (); 
void hide_mouse_pointer(); 
void get_mouse_position (int *x, int *y, int *mousebutton); 
void show_mouse_coordinate(); 
void clear_mouse_coordinate (); 
 
union REGS iReg, oReg; 
struct SREGS segregs; 
int c, numbuttons, oldmouse, mousebutton, movx, movy; float mouseversion;
int Quit; 
int x,y,Buttons,OldX,OldY; 
 
void main () 
 { _setcursortype (_NOCURSOR);
   clrscr(); 
   gotoxy (15,5);cputs ("Mouse Movement Demonstration Program");
   gotoxy (15,6);cputs ("Written For PDRM staff by Kamal Zamli");
   show_mouse_pointer();                            
   gotoxy(18,9);puts("*****************************************");
   gotoxy (18,10);puts("Click Here to Quit");      
   gotoxy(18,11);puts("**************************************");
   Quit=0; 
   OldX=-1; 
   OldY=-1; 
   while (!Quit) 
    { 
     get_mouse_position(&x,&y,&Buttons);
     if ((OldX != x) || (OldY != y)) 
       { 
        clear_mouse_coordinate(); 
        show_mouse_coordinate();
        OldX=x; 
        OldY=y; 
       } 
    if (((x>=15) & (x<=35)) & ((y==9)) & (Buttons==1)) 
      { 
        Quit=1; 
      }
 } 
 hide_mouse_pointer(); 
 reset_mouse(); 
 clrscr();
 _setcursortype (_NORMALCURSOR); 
} 
 
void clear_mouse_coordinate() 
 { 
  hide_mouse_pointer();
  gotoxy (25,1); puts (" "); 
  gotoxy (25,2); puts (" ");
  show_mouse_pointer(); 
 } 
 
void show_mouse_coordinate () 
 { 
  char xstring[10],ystring[10];
  hide_mouse_pointer(); 
  sprintf (xstring,"x = %d",x); 
  sprintf (ystring,"y= %d",y); 
  gotoxy (25,1);puts (xstring); 
  gotoxy (25,2);puts (ystring);
  show_mouse_pointer(); 
 } 
 
int initialize_mouse () 
 { 
  iReg.x.ax = 0; 
  int86(0x33, &iReg, &oReg); 
  if (oReg.x.ax == 0xFFFF) 
   return (oReg.x.bx);
  else return 0; 
} 
 
void reset_mouse () 
 { 
  iReg.x.ax = 0; 
  int86 (0x33, &iReg,&oReg); 
 } 
 
void show_mouse_pointer () 
 { 
  iReg.x.ax = 1; 
  int86 (0x33,&iReg, &oReg); 
 } 
 
void hide_mouse_pointer () 
 { 
  iReg.x.ax = 2; 
  int86(0x33, &iReg, &oReg); 
 
 }
 
 void get_mouse_position (int *x, int *y,int *mousebutton) 
{ 
 iReg.x.ax = 3; 
 int86 (0x33, &iReg, &oReg);
 *x = oReg.x.cx / 8; 
 *y = oReg.x.dx / 8; 
 *mousebutton = oReg.x.bx; 
 } | 
Partager