| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 877 人关注过本帖
标题:TC编界面遇到问题
只看楼主 加入收藏
herendagao
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2006-5-3
结帖率:100%
收藏
 问题点数:0 回复次数:5 
TC编界面遇到问题

以下是我的程序源代码
#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();
}
问题是这样的:我想做出像鼠标箭头那样的效果,但鼠标移动位置之后我想用原先位置的图像将该处的“箭头”擦去,结果失败了。程序中||| |||只见的代码是我想用来实现这一效果的关键代码。
希望各位大哥大姐帮帮忙,谢谢!

搜索更多相关主题的帖子: 界面 
2006-09-27 14:37
cdmalcl
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:4091
专家分:524
注 册:2005-9-23
收藏
得分:0 

#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);
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);
mx=x;my=y;
p=buf1;
while(1)
{
if(kbhit())
{
ch=getch();
if(ch==27)
exit();
}
getmouse(&button,&x,&y);

if((x!=mx||y!=my)&&my>=0)
{
putimage(mx,my,p,0);
free(buf1);
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);
mx=x;my=y;
p=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();
}

程序写的挺有意思的
没有时间仔细看你的程序
但我的直觉认为你的程序好象有不少多余的地方

我一般存储鼠标背景图一般都是用数组
从不用putimage
感觉还是putimage效率未必比数组高
putimage还要时刻free 挺麻烦的

2006-09-27 15:42
herendagao
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2006-5-3
收藏
得分:0 

谢谢你.


2006-09-27 20:50
herendagao
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2006-5-3
收藏
得分:0 

你得代码中,if((x!=mx||y!=my)&&my>=0)
{
putimage(mx,my,p,0);
free(buf1);
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);
mx=x;my=y;
p=buf1;
}
已经free(buf1)了,p=buf1还有效吗?


2006-09-27 20:55
cdmalcl
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:4091
专家分:524
注 册:2005-9-23
收藏
得分:0 
无效
2006-09-27 21:04
herendagao
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2006-5-3
收藏
得分:0 
刚才没仔细看,现在明白了.
if((x!=mx||y!=my)&&my>=0)
{
putimage(mx,my,p,0);
free(buf1);
///putimage(x,y,buf2,0);///
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);*/
mx=x;my=y;
p=buf1;
}
但是在我重新体会你的思想的时候不小心把你的代码中的/*  */之间的代码放在了///   ///之间,结果还是有痕迹残留 

2006-09-27 21:20
快速回复:TC编界面遇到问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019785 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved