#<dos.h>
#<graphics.h>
#<conio.h>
union REGS regs;
X__max,Y__max,x_max,y_max;
void Initgr(void) /*屏幕化成图形模式*/
{ w,h,grdriver=DETECT,grmode;
initgraph(&grdriver,&grmode,\"\");/*在双引号中可加你tc放路径但要在tc里有EGAVGA.BGI这个来图形*/
(graphresult)/*若不成功退出*/
{prf(\"\\n 在双引号中可加你tc放路径但要在tc里有EGAVGA.BGI这个来图形.\\n\");
exit(1);
}
X__max=getmaxx;/*求横向象点坐标数*/
Y__max=getmaxy;/*求纵向象点坐标数*/
getaspectratio(&w,&h);/*求纵横比*/
x_max=1000; /*设置屏幕坐标宽度*/
y_max=x_max*(float)Y__max*h/((float)X__max*w);
}
Msinit( Xlo, Xhi, Ylo, Yhi)/*鼠标化*/
{ retcode;
regs.x.ax=0;/*化鼠标*/
86(0x33,®s,®s);
retcode=regs.x.ax;
(retcode0) 0;
regs.x.ax=7;/*设置鼠标X方向移动范围*/
regs.x.cx=Xlo;
regs.x.dx=Xhi;
86(0x33,®s,®s);
regs.x.ax=8;/*设置鼠标Y方向移动范围*/
regs.x.cx=Ylo;
regs.x.dx=Yhi;
86(0x33,®s,®s);
regs.x.ax=15;/*设置mickey和象素比这各会影响鼠标移动速度*/
regs.x.cx=()(x_max/X__max);
regs.x.dx=()(y_max/Y__max);
86(0x33,®s,®s);
retcode;
}
Msread( *px, *py, *pbuttons)/*读鼠标位置及状态*/
{ x0=320,y0=240,but0=0;
x,y,ch;
do{
(kbhit){
ch=getch;
(ch13){
*pbuttons=1;
-1;
}
ch; /*返回键盘输入*/
}
regs.x.ax=3; /*功能3读鼠标位置及状态*/
86(0x33,®s,®s);
x=regs.x.cx;/*返回鼠标当前位置X坐标*/
y=regs.x.dx;/*返回鼠标当前位置Y坐标*/
*pbuttons=regs.x.bx;/*返回鼠标当前状态*/
}while(xx0&&yy0&&*pbuttonsbut0);
/*当鼠标状态改变或位置改变终止循环*/
but0=*pbuttons;/*将鼠标状态保存到静态变量中*/
x0=x;y0=y;/*将鼠标位置保存到静态变量中*/
*px=x;*py=()(y_max-y);
-1;
}
Xpixel( x)/*由象素坐标变换为屏幕坐标*/
{ ()((long)X__max*x/x_max);}
Ypixel( y)
{ Y__max-()((long)Y__max*y/y_max);}
void Cursor( x, y) /*显示十字光标*/
{ X=Xpixel(x),Y=Ypixel(y),color;
char *str=\" \\0\";
line(X-8,Y,X-3,Y);
line(X,Y-8,X,Y-4);
line(X+3,Y,X+8,Y);
line(X,Y+4,X,Y+8);
color=getcolor;
color(BLACK);
outtextxy(X__max-100,10,str);/*删除前次显示值*/
sprf(str,\"%d,%d\",x,y);
color(WHITE);
outtextxy(X__max-100,10,str);/*在屏幕右上角显示当前光标坐标*/
color(color);
}
{ buttons,X,Y,x,y,a,b;
char i;
Initgr;/*化图形屏幕*/
color(EGA_LIGHTRED);/*设置屏幕前景色*/
line(1,1,X__max-1,1); /*在屏幕 4周画矩形*/
line(1,1,1,Y__max-1);
line(X__max-1,1,X__max-1,Y__max-1);
line(1,Y__max-1,X__max-1,Y__max-1);
color(EGA_WHITE);
prf(\"\\n 按鼠标右键终止\\n\");
prf(\" 然后按任意键退出\");
writemode(XOR_PUT);/*设置屏幕输出模式*/
Msinit(0,()x_max,0,()y_max);/*化鼠标*/
a=x_max;b=y_max;
x=0;
Cursor(a,b); /*在a=x_max;b=y_max;处画指针*/
while(x!=2)
{Msread(&X,&Y,&x);
Cursor(a,b); /*删除的前鼠标,屏幕输出模式关系*/
(x1){
a=()(X*1.0/x_max*X__max);b=()((y_max-Y)*1.0/y_max*Y__max);
circle(a,b,1); } /*画点*/
Cursor(X,Y);
a=X;b=Y;
}
Cursor(X,Y);/*再次把原来指针削掉*/
getch;
closegraph;}
最新评论