include dos include stdio include conio include graphics include proce

 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
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <process.h>
#include <stdlib.h>
REGS regs;
void InitMouse(int *nbuttons, int *OK)
{
regs.x.ax=0;
int86(0x33, &regs, &regs);
*OK=regs.x.ax;
*nbuttons=regs.x.bx;
}
void ShowMouse(void)
{
regs.x.ax=1;
int86(0x33, &regs, &regs);
}
void HideMouse(void)
{
regs.x.ax=2;
int86(0x33, &regs, &regs);
}
void ReadMouse(int *x, int *y, int *buttons)
{
regs.x.ax=3;
int86(0x33, &regs, &regs);
*buttons=regs.x.bx;
*x=regs.x.cx;
*y=regs.x.dx;
}
void Click(int &x, int &y)
{
do
{
regs.x.ax=3;
int86(0x33, &regs, &regs);
if (regs.x.bx&2) exit(EXIT_SUCCESS);
}
while(!(regs.x.bx&1));
regs.x.ax=3;
int86(0x33, &regs, &regs);
x=regs.x.cx;
y=regs.x.dx;
}
void main(void)
{
int nbuttons, OK, x, y, x1, y1, but, c;
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "Z:\\BC31\\bgi\\");
InitMouse( &nbuttons, &OK);
if (OK==-1) printf("Mouse initilized successfully!\n");
printf("Your mouse seems to have %d buttons.\n",nbuttons);
printf("Right-click to exit\n");
ShowMouse();
Click(x,y);
while (1)
{
Click(x1,y1);
HideMouse();
line(x,y,x1,y1);
x=x1;
y=y1;
ShowMouse();
}
/* do {ReadMouse(&x,&y,&but);} while(!but);
do {ReadMouse(&x,&y,&but);} while(but);
while (1)
{
do {ReadMouse(&x1,&y1,&but);} while(!but);
if (but&2) break;
do {ReadMouse(&x1,&y1,&but);} while(but);
HideMouse();
line(x, y, x1, y1);
x=x1;
y=y1;
ShowMouse();
} */
closegraph();
}