在Tc2.0下的鼠标控制程序
2008-03-08 21:30:11 来源:WEB开发网核心提示:程序很短,不过效果还可以,在Tc2.0下的鼠标控制程序,#include<stdio.h>#include<graphics.h>#include<dos.h>#include<conio.h>#define TIMER 0x1c#ifdef __cplusplus#define __CPPARGS ...#else#
程序很短,不过效果还可以。
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<conio.h>
#define TIMER 0x1c
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
int TimerCounter=0;
void interrupt ( *oldhandler)(__CPPARGS);
void interrupt newhandler(__CPPARGS){
TimerCounter++;
oldhandler();
}
void SetTimer(void interrupt (*IntPRoc)(__CPPARGS)){
oldhandler=getvect(TIMER);
disable();
setvect(TIMER,IntProc);
enable();
}
void CloseTimer(){
disable();
setvect(TIMER,oldhandler);
enable();
}
void mshow(){
union REGS ireg,oreg;
ireg.x.ax=1;
int86(0x33,&ireg,&oreg);
}
void getmxy(double *x,double *y){
union REGS ireg,oreg;
ireg.x.ax=3;
int86(0x33,&ireg,&oreg);
*x=oreg.x.cx*1.0;
*y=oreg.x.dx*1.0;
}
resetp(int x,int y,int a,int b){
cleardevice();
setcolor(1);
rectangle(10,10,629,339);
line(x,y,a,b);
setcolor(4);
rectangle(a-5,b-5,a+5,b+5);
setcolor(2);
pieslice(x,y,0,360,10);
setcolor(1);
}
void main(void){
int gdriver=EGA,gmode=EGAHI,key;
double ax,ay,vx,vy,px,py,mx,my;
int curpage=0;
initgraph(&gdriver,&gmode,"d:\\software\\turboc2");
vx=0.0,vy=0.0,px=getmaxx()/2.0,py=getmaxy()/2.0,ax=ay=0;
mshow();
getmxy(&mx,&my);
setbkcolor(15);
setfillstyle(SOLID_FILL,2);
setactivepage(curpage);
resetp((int)px,(int)py,(int)mx,(int)my);
setvisualpage(curpage);
SetTimer(newhandler);
while(1){
if(kbhit())break;
if(TimerCounter>1){
TimerCounter=0;
getmxy(&mx,&my);
px=px+vx;
py=py+vy;
if(px>=629 px<=10)vx=-vx;
if(py>=339 py<=10)vy=-vy;
vx=vx*0.97+ax;
vy=vy*0.97+ay;
ax=(mx-px)*0.01;
ay=(my-py)*0.01;
curpage=curpage==0?1:0;
setactivepage(curpage);
resetp((int)px,(int)py,(int)mx,(int)my);
setvisualpage(curpage);
}
}
CloseTimer();
}
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<conio.h>
#define TIMER 0x1c
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
int TimerCounter=0;
void interrupt ( *oldhandler)(__CPPARGS);
void interrupt newhandler(__CPPARGS){
TimerCounter++;
oldhandler();
}
void SetTimer(void interrupt (*IntPRoc)(__CPPARGS)){
oldhandler=getvect(TIMER);
disable();
setvect(TIMER,IntProc);
enable();
}
void CloseTimer(){
disable();
setvect(TIMER,oldhandler);
enable();
}
void mshow(){
union REGS ireg,oreg;
ireg.x.ax=1;
int86(0x33,&ireg,&oreg);
}
void getmxy(double *x,double *y){
union REGS ireg,oreg;
ireg.x.ax=3;
int86(0x33,&ireg,&oreg);
*x=oreg.x.cx*1.0;
*y=oreg.x.dx*1.0;
}
resetp(int x,int y,int a,int b){
cleardevice();
setcolor(1);
rectangle(10,10,629,339);
line(x,y,a,b);
setcolor(4);
rectangle(a-5,b-5,a+5,b+5);
setcolor(2);
pieslice(x,y,0,360,10);
setcolor(1);
}
void main(void){
int gdriver=EGA,gmode=EGAHI,key;
double ax,ay,vx,vy,px,py,mx,my;
int curpage=0;
initgraph(&gdriver,&gmode,"d:\\software\\turboc2");
vx=0.0,vy=0.0,px=getmaxx()/2.0,py=getmaxy()/2.0,ax=ay=0;
mshow();
getmxy(&mx,&my);
setbkcolor(15);
setfillstyle(SOLID_FILL,2);
setactivepage(curpage);
resetp((int)px,(int)py,(int)mx,(int)my);
setvisualpage(curpage);
SetTimer(newhandler);
while(1){
if(kbhit())break;
if(TimerCounter>1){
TimerCounter=0;
getmxy(&mx,&my);
px=px+vx;
py=py+vy;
if(px>=629 px<=10)vx=-vx;
if(py>=339 py<=10)vy=-vy;
vx=vx*0.97+ax;
vy=vy*0.97+ay;
ax=(mx-px)*0.01;
ay=(my-py)*0.01;
curpage=curpage==0?1:0;
setactivepage(curpage);
resetp((int)px,(int)py,(int)mx,(int)my);
setvisualpage(curpage);
}
}
CloseTimer();
}
更多精彩
赞助商链接