TC图形编程-鼠标放大镜[HungryAnt制作][原创]
2007/08/29 22:04
/*********************************作者:HungryAnt
姓名:孙麟
E-mail:ljsunlin@126.com
QQ:517377100
blog:http://hi.baidu.com/zhongji/blog
*********************************/
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#define HA_MOUSE 0X33
int m_poly[8]={0,0,5,7,0,9,0,0};/*鼠标*/
int m_now_poly[8]={0,0,5,7,0,9,0,0};
int re[10][6];/*储存鼠标经过前的像素颜色*/
void ha_mouse(){
int i,j,k,x=-1,y=-1,flag=0,color;
union REGS inregs,outregs;
inregs.x.ax=3;
setcolor(LIGHTGRAY);
rectangle(1,1,62,62);
setcolor(DARKGRAY);
rectangle(0,0,63,63);
while(!bioskey(1)){
int86(HA_MOUSE,&inregs,&outregs);
if(x!=outregs.x.cx || y!=outregs.x.dx){
if(flag){
for(j=0;j<10;j++)/*恢复上次鼠标一定范围内的像素颜色*/
for(i=0;i<6;i++)
putpixel(x+i,y+j,re[j][i]);
}
flag=1;
for(j=0;j<10;j++)/*储存鼠标一定范围内的像素颜色*/
for(i=0;i<6;i++)
re[j][i]=getpixel(outregs.x.cx+i,outregs.x.dx+j);
gotoxy(2,15);
printf("%-3d,%-3d",outregs.x.cx,outregs.x.dx);
for(i=0;i<8;i++){/*确定鼠标各顶点位置*/
m_now_poly[i]=m_poly[i]+outregs.x.cx;
i++;
m_now_poly[i]=m_poly[i]+outregs.x.dx;
}
for(j=0;j<20;j++)
for(i=0;i<20;i++){
color=getpixel(outregs.x.cx+i,outregs.x.dx+j);
setfillstyle(SOLID_FILL,color);
bar(i*3+2,j*3+2,i*3+4,j*3+4);
}
setcolor(WHITE);
drawpoly(4,m_now_poly);/*显示鼠标框架*/
floodfill(m_now_poly[0]+1,m_now_poly[1]+5,WHITE);/*填充鼠标,注意以白色填充,当遇到白色背景时会不能完全填充*/
}
x=outregs.x.cx;/*存鼠标坐标,供恢复使用*/
y=outregs.x.dx;
}
}
ha_graph(){/*图形模式初始化*/
int gd=DETECT,gm,errorcode;
initgraph(&gd,&gm,"");
errorcode = graphresult();
if (errorcode != grOk){
printf("Graphics error: %s",grapherrormsg(errorcode));
printf("Author:HungryAnt");
getch();
exit(1);
}
}
int main(){
int i;
ha_graph();
/*for(i=0;i<639;i+=30){
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(i,0,i+14,479);
setfillstyle(SOLID_FILL,DARKGRAY);
bar(i+15,0,i+29,479);
}*/
setbkcolor(BLACK);
settextstyle(0,0,3);
setcolor(WHITE);
outtextxy(251,201,"HungryAnt");
setcolor(LIGHTBLUE);
outtextxy(250,200,"HungryAnt");
ha_mouse();
}