以下是我的程序源代码
#include<stdio.h>
#include<dos.h>
#include<graphics.h>
#include<malloc.h>
union REGS i,o;
void initmouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
}
void getmouse(int *but,int *mx,int *my)
{
i.x.ax=3;
i.x.bx=0;
int86(0x33,&i,&o);
*but=o.x.bx;
*mx=o.x.cx;
*my=o.x.dx;
}
void opengraph()
{
int gdriver=DETECT,gmode;
registerbgidriver(EGAVGA_driver);
initgraph(&gdriver,&gmode," ");
}
void intgraph(int color1,int color2,int color3,int color4)
{
setcolor(color1);
rectangle(250,140,330,170);
outtextxy(255,153,"BEGIN");
setcolor(color2);
rectangle(250,180,330,210);
outtextxy(255,193,"CHARACTER");
setcolor(color3);
rectangle(250,220,330,250);
outtextxy(255,233,"CLASS");
setcolor(color4);
rectangle(250,260,330,290);
outtextxy(255,273,"EXIT");
}
void drawgraphson1()
{
setcolor(8);
rectangle(250,170,330,200);
outtextxy(255,183,"Tom Smith");
rectangle(250,210,330,240);
outtextxy(255,223,"John Green");
}
void drawgraphson2()
{
setcolor(8);
rectangle(250,160,330,190);
outtextxy(255,173,"Simple");
rectangle(250,200,330,230);
outtextxy(255,213,"Normal");
rectangle(250,240,330,270);
outtextxy(255,253,"Experient");
}
main()
{
int c1=8,c2=8,c3=8,c4=8,size;
int button,x,y,mx=0,my=-1;
void *buf,*buf1,*buf2,*p;
char ch;
opengraph();
setbkcolor(0);
setcolor(15);
setfillstyle(1,15);
circle(100,100,2);
floodfill(100,100,15);
size=imagesize(99,99,101,101);
buf2=malloc(size);
if(!buf2)
exit();
getimage(99,99,101,101,buf2);
cleardevice();
setcolor(15);
rectangle(100,100,440,380);
size=imagesize(250,140,330,290);
buf=malloc(size);
if(!buf)
exit();
getimage(250,140,330,290,buf);
initmouse();
intgraph(8,8,8,8);
while(1)
{
if(kbhit())
{
ch=getch();
if(ch==27)
exit();
}
getmouse(&button,&x,&y);
||| size=imagesize(x,y,x+2,y+2);
buf1=malloc(size);
if(buf1==NULL)
exit();
getimage(x,y,x+2,y+2,buf1);
putimage(x,y,buf2,0);
if((x!=mx||y!=my)&&my>=0)
putimage(mx,my,p,0);
mx=x;my=y;
p=buf1;
free(buf1); |||
if(x>250&&x<330)
{
if(y>140&&y<170)
{
c1=15;
intgraph(c1,8,8,8);
if(button==1)
{
closegraph();
break;
}
}
else if(y>180&&y<210)
{
c2=15;
intgraph(8,c2,8,8);
if(button==1)
{
putimage(250,140,buf,0);
drawgraphson1();
break;
}
}
else if(y>220&&y<250)
{
c3=15;
intgraph(8,8,c3,8);
if(button==1)
{
putimage(250,140,buf,0);
drawgraphson2();
break;
}
}
else if(y>260&&y<290)
{
c4=15;
intgraph(8,8,8,c4);
if(button==1)
{
closegraph();
break;
}
}
else
intgraph(8,8,8,8);
}
else
intgraph(8,8,8,8);
}
getch();
}
问题是这样的:我想做出像鼠标箭头那样的效果,但鼠标移动位置之后我想用原先位置的图像将该处的“箭头”擦去,结果失败了。程序中||| |||只见的代码是我想用来实现这一效果的关键代码。
希望各位大哥大姐帮帮忙,谢谢!