| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 388 人关注过本帖
标题:请教一个鼠标程序中的一个变量
只看楼主 加入收藏
leopardxp
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2007-7-26
结帖率:100%
收藏
 问题点数:0 回复次数:0 
请教一个鼠标程序中的一个变量

这是一个鼠标作图的程序,请问“xm”是什么作用?只有定义,没有赋值啊~~~~~~~~但程序能正常编译运行~

/* Note:Your choice is C IDE */
#include<dos.h>
#include<stdio.h>
#include<graphics.h>

union REGS regs;
int init();
int read();
void cursor(),newxy();
int xmin,xmax,ymin,ymax,x_max=639,y_max=479;
main()
{
int buttons,xm,ym,x0,y0,x,y;
char str[100];
int gdrive,gmode;
registerbgidriver(EGAVGA_driver);
gdrive=DETECT;
initgraph(&gdrive,&gmode,"");
clrscr();
rectangle(0,0,x_max,y_max);
setfillstyle(SOLID_FILL,BLUE);
bar(1,1,x_max-1,y_max-1);
outtextxy(3,15,"move mouse using any button.");
outtextxy(285,15,"quit");
xmin=2;
xmax=x_max-1;
ymin=8;
ymax=y_max-2;
setwritemode(XOR_PUT);
if(init(xmin,xmax,ymin,ymax)==0) /* 调用init函数对鼠标初始化 */
{
printf("Mouse or Mouse Driver Absent,Please install! ");
delay(5000);
exit(1);
}
x=320;
y=240;
cursor(x,y); /* 置十字光标在屏幕中心。 */
for(;;)
{
newxy(&x,&y,&buttons);
if(x>=280&&x<=330&&y>=12&&y<=33&&buttons) /* 十字光标移到quit处时*/
{
cleardevice();
exit(0); /* 回到系统 */
}
}
}

void cursor(int x,int y) /* 画十字光标函数 */
{
int x1,x2,y1,y2;
x1=x-4;
x2=x+4;
y1=y-3;
y2=y+3;
line(x1,y,x2,y);
line(x,y1,x,y2);
}

int init(int xmi,int xma,int ymi,int yma) /* 鼠标初始化函数 */
{
int retcode;
regs.x.ax=0;
int86(51,&regs,&regs);
retcode=regs.x.ax;
if(retcode==0)
return 0; /* 返回0表示鼠标或鼠标驱动程序未安装 */
regs.x.ax=7;
regs.x.cx=xmi;
regs.x.dx=xma;
int86(51,&regs,&regs);
regs.x.ax=8;
regs.x.cx=ymi;
regs.x.dx=yma;
int86(51,&regs,&regs); /* 表示鼠标和驱动程序已安装 */
return retcode;
}
int read(int*mx,int*my,int*mbutt) /* 读鼠标的位置和按钮状态函数*/
{
int xx0=*mx,yy0=*my,but0=0;
int xnew,ynew;
do
{
regs.x.ax=3;
int86(51,&regs,&regs);
xnew=regs.x.cx;
ynew=regs.x.dx;
*mbutt=regs.x.bx;
}while(xnew==xx0&&ynew==yy0&&*mbutt==but0);
*mx=xnew;
*my=ynew;
if(*mbutt)
{
*mx=xnew;
*my=ynew;
return -1;
}
else
{
*mx=xnew;
*my=ynew;
return 1;
}
}

void newxy(int*mx,int*my,int*mbutt) /* 是否有按钮按下,若按下,在新位置画十字 */
{
int ch,xx0=*mx,yy0=*my,x,y;
int xm,ym;
ch=read(&xm,&ym,mbutt);
if(ch>0)
{
cursor(xx0,yy0);
cursor(xm,ym);
}
else
{
cursor(xx0,yy0);
cursor(xm,ym);
putpixel(xm,ym,7);
}
*mx=xm;
*my=ym;
}


搜索更多相关主题的帖子: 鼠标 变量 
2007-08-10 21:07
快速回复:请教一个鼠标程序中的一个变量
数据加载中...
 
   



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

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