主题:Tc2.0下的鼠标控制
这两天看c的中断,于是把以前用vb做的东西都一个一个翻译过来,不用再去想新的idear,感觉很好。下面是一个tc里面用到鼠标的程序,另外用到了前人做俄罗斯方块的部分函数(其实对时钟中断,我是一点不懂)。程序很短,不过效果还可以。
#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();
}