分类: C/C++
2008-05-25 00:06:51
do{ /* 或 return getch(); 返回ASCII码值*/
if(kbhit()) return bioskey(0);/* 若有键盘点击返回键值*/
regs.x.ax=3;
int86(0x33,®s,®s);
*px=regs.x.cx; /* x坐标*/
*py=regs.x.dx; /* y坐标*/
*buttons=regs.x.bx; /* 返回鼠标击键状态:
0未点击 1点击左键
2点击右键 3点击双键*/
}while(*px==x_old&&*py==y_old&&*buttons==but_old);
MouseOff(x_old,y_old);/* 原位置异或消去擦除,并还原*/
but_old=*buttons;
x_old=*px;
y_old=*py;
MouseOn(*px,*py); /* 新位置显示*/
return -1;
}
int MouseInbox(int x1,int y1,int x2,int y2,int x,int y)
{
return((x>=x1&&x<=x2&&y>=y1&&y<=y2)?1:0); /* 若在预定区域就返回 1 */
}
int MouseInit()
{ /* 初始化鼠标*/
int recored;
MouseMath(); /* 初始化时先计算*/
regs.x.ax=0;
int86(0x33,®s,®s);/* 调用中断检测*/
recored=regs.x.ax;
if(recored==0)
{ printf("Mouse not found !\n");
getch();return 0;
}
regs.x.ax = 1; /* 显示鼠标*/
int86(0x33,®s,®s);
return recored;
}
void main()
{
int msx,msy,msz,order;
int gmode=0,gdriver=DETECT;/* 和gdriver = VGA,gmode = VGAHI是同样效果 */
registerbgidriver(EGAVGA_driver);/* 注册BGI驱动后可以不需要.BGI文件的支持运行 */
initgraph(&gmode,&gdriver,"");
if(graphresult())
{
printf ("Graphics isn't available...");
getch();exit(1);
}
MouseInit();/* 初始化*/
setcolor(1);
rectangle(140,80,500,110);
setfillstyle(8,2);
floodfill(150,100,1);setcolor(15);
outtextxy(182,85,"Move to me to change mouse's shape");
outtextxy(180,100,"Click me to quit ... QQ: 527274766");
for(;;)
{
order=MouseRead(&msx,&msy,&msz);
if(order==283) break;
if( MouseInbox(140,80,500,110,msx,msy))
{ /* 改变鼠标形状*/
if(Mousekind!=1+0*2+9*4+15*64)
{
MouseOff(msx,msy);/* 擦除*/
Mousekind=1+0*2+9*4+15*64;/* 改变*/
MouseMath();/* 重新计算鼠标形状*/
}
if(msz==1) { closegraph();exit(0);}
}
else
{ /* 还原鼠标形状*/
if(Mousekind!=0+1*2+15*4+2*64)
{
MouseOff(msx,msy);
Mousekind=0+1*2+15*4+2*64;
MouseMath();
}
}
}
}