不行呀!下面是源代码:
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<graphics.h>
union REGS regs;
void cursor(int x,int y)
;
int init(int xmi,int xma,int ymi,int yma);
void newxy(int *mx,int *my,int *mbutt);
int read(int *mx,int *my,int *mbutt)
;
int xmin,xmax,ymin,ymax,x_max=639,y_max=479;
main()
{
int buttons,xm,ym,x0,y0,x,y;
char str[100];
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\\tc30\\bgi");
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) {
printf("mouse or mouse driver absent ,please install!");
delay(5000);
exit(1);
}
x=320;
y=240;
cursor(x,y);(在这一步之后,转到DOS的图形界面后,图形中会有一个十字形,就是鼠标的形状,但是和鼠标的移动没有建立联系,是不是要在弄一个鼠标驱动程序?
)
for(;;)
{
newxy(&x,&y,&buttons);
if(x>=280&&x<330&&y>12&&y<33&&buttons) {
cleardevice();
exit(1);
}
}
}
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,®s,®s);
retcode=regs.x.ax;
if(retcode==0)
return 0;
regs.x.ax=7;
regs.x.cx=xmi;
regs.x.dx=xma;
int86(51,®s,®s);
regs.x.ax=8;
regs.x.cx=ymi;
regs.x.dx=yma;
int86(51,®s,®s);
return retcode;
}
int read(int *mx,int *my,int *mbutt)
{
int xx0=*mx,yy0=*my,but0=0,mb;
int xnew,ynew;
do{
regs.x.ax=3;
int86(51,®s,®s);
xnew=regs.x.cx;
ynew=regs.x.dx;
*mbutt=regs.x.bx;
}
while(xnew=xx0 && ynew==yy0 && *mbutt==but0 ) ;
*mx=xnew;
*my=ynew;
mb=(*mbutt);
if(mb)
{
if(mb==1)
return 1;
if(mb==2)
return 2;
return 3;
}
else
return 0;
}
void newxy(int *mx,int *my,int *mbutt)
{
int ch,xx0=*mx,yy0=*my,x,y;
int xm,ym;
ch=read(&xm,&ym,mbutt);
switch(ch) {
case 0:
cursor(xx0,yy0);
cursor(xm,ym);
break;
case 1:
cursor(xx0,yy0);
cursor(xm,ym);
circle(xm,ym,6);
break;
case 2:
cursor(xx0,yy0);
cursor(xm,ym);
rectangle(xm,ym,xm+12,ym+12);
break;
case 3:
cursor(xx0,yy0);
cursor(xm,ym);
putpixel(xm,ym,7);
break;
}
*mx=xm;
*my=ym;