#include
"Conio.h"
#include
"dos.h"
#include
"graphics.h"
#define
closegr
closegraph
union
REGS
regs;
int
X_max,Y_max
;
void
initgr(void)
/*
BGI初始化
*/
{
int
gd
=
DETECT,
gm
=
0;
registerbgidriver(EGAVGA_driver);
initgraph(&gd,
&gm,
"");
X_max
=
getmaxx();
/*求横、纵向象点坐标数*/
Y_max
=
getmaxy();
}
int
Msinit(int
Xlo,int
Xhi,int
Ylo,int
Yhi)/*鼠标初始化*/
{
int
retcode;
regs.x.ax
=
0;
/*初始化鼠标*/
int86(0x33,®s,®s);
retcode
=
regs.x.ax;
if(retcode
==
0)
return
0;
regs.x.ax
=
7;
/*设置鼠标X方向的移动范围*/
regs.x.cx
=
Xlo;
regs.x.dx
=
Xhi;
int86(0x33,®s,®s);
regs.x.ax
=
8;
/*设置鼠标Y方向的移动范围*/
regs.x.cx
=
Ylo;
regs.x.dx
=
Yhi;
int86(0x33,®s,®s);
return
retcode;
}
int
Msread(int
*px,int
*py,int
*pbuttons)/*读鼠标位置及状态*/
{static
int
x0
=
320,y0
=
240,but0
=
0;
int
xnew,ynew,ch;
do
{
regs.x.ax
=
3;
/*调用功能3,读鼠标位置及状态*/
int86(0x33,®s,®s);
xnew
=
regs.x.cx;
/*返回鼠标当前的位置的X坐标*/
ynew
=
regs.x.dx;
/*返回鼠标当前的位置的Y坐标*/
*pbuttons
=
regs.x.bx;
/*返回鼠标当前的状态*/
}
while(xnew==x0&&ynew==y0&&*pbuttons==but0);
/*当鼠标状态改变或位置改变终止循环*/
but0
=
*pbuttons;
/*将鼠标状态保存到静态变量中*/
x0
=
xnew;y0
=
ynew;
/*将鼠标位置保存到静态变量中*/
*px
=
xnew;*py
=
ynew;
return
-1;
}
int
main(void)
{
int
a
=
0,b
=
0,x
=
0,X,Y;
char
*str
=
"
";
initgr();
Msinit(0,X_max,0,Y_max);
while(x!=2)
{Msread(&X,&Y,&x);
setcolor(BLACK);
sprintf(str,"%d,%d",a,b);
outtextxy(X_max-100,10,str);
putpixel(a,b,0);
setcolor(WHITE);
sprintf(str,"%d,%d",X,Y);
outtextxy(X_max-100,10,str);
putpixel(X,Y,3);
a
=
X,b
=
Y;
}
closegr();
return
0;
}
复制代码