- int getx(void){message();return x;} //获得鼠标x值
- int gety(void){message();return y;} //获得鼠标y值
- int getlbx(void){mousekeymessage();return lbx;} //获得鼠标左键按下的x值
- int getlby(void){mousekeymessage();return lby;} //获得鼠标左键按下的y值
- int getlex(void){mousekeymessage();return lex;} //获得鼠标左键松开的x值
- int getley(void){mousekeymessage();return ley;} //获得鼠标左键松开的y值
- int getrbx(void){mousekeymessage();return rbx;} //获得鼠标右键按下的x值
- int getrby(void){mousekeymessage();return rby;} //获得鼠标右键按下的y值
- int getrex(void){mousekeymessage();return rex;} //获得鼠标右键松开的x值
- int getrey(void){mousekeymessage();return rey;} //获得鼠标右键松开的y值
- //获得鼠标左键按下的次数
- int getleftnum(void){mousekeymessage();return leftnum;}
- //获得鼠标右键按下的次数
- int getrightnum(void){mousekeymessage();return rightnum;}
- int getkey(void){message();return key;} //获得鼠标key值
- //显示鼠标座标
- void showxy(void){gotoxy(1,1);cout<<"x="<<x<<" y="<<y<<" key="<<key<<endl;}
- int yesno(int,int,int,int);//判断鼠标是否在指定范围
- void run(void far interrupt(far *p)(),int nn);// 用户鼠标程序的运行
- void close(void); //消除用户鼠标程序的运行
- };
- //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- void MOUSE::show_message(void)
- {
- cout<<"Mouse num:"<<num<<endl;
- cout<<"Mouse form:"<<form<<endl;
- cout<<"Mouse showsection:"<<bx<<","<<by<<","<<ex<<","<<ey<<endl;
- }
- void MOUSE::init(void)
- {
- union REGS r;
- flag=0;
- if(getvect(0x33)!=0L)
- { r.x.ax=0;
- int86(0x33,&r,&r);
- if(r.x.ax==0){cout<<"NOT INSTALLED MOUSE !";exit(0);}
- if(r.x.ax!=0){
- flag=1;num=r.x.bx;
- shape();
- if(!chart)
- {
- r.h.ah=0x0f;
- int86(0x10,&r,&r);
- if(r.h.al==0||r.h.al==1)winxsize=16;
- chart=1;
- }}
- }
- }
- void MOUSE::shape()
- {
- if(flag)
- { _ES=FP_SEG(form->image);
- _DX=FP_OFF(form->image);
- _CX=form->y;
- _BX=form->x;
- _AX=0x09;
- geninterrupt(0x33);
- rx=form->x;
- ry=form->y;
- }
- }
- void MOUSE::setshape(int n)
- {
- switch (n)
- {
- case 0:form=&Mouse0;break;
- case 1:form=&Mouse1;break;
- case 2:form=&Mouse2;break;
- case 3:form=&Mouse3;break;
- case 4:form=&Mouse4;break;
- case 5:form=&Mouse5;break;
- case 6:form=&Mouse6;break;
- case 7:form=&Mouse7;break;
- case 8:form=&Mouse8;break;
- default:break;
- }
- shape();
- }
- inline void MOUSE::show(void)
- {
- union REGS r;
- if(flag)
- {
- r.x.ax=1;
- int86(0x33,&r,&r);
- FLAG=1;
- }
- }
- inline void MOUSE::hide(void)
- {
- union REGS r;
- if((FLAG)&&(flag))
- {
- r.x.ax=2;
- int86(0x33,&r,&r);
- FLAG=0;
- }
- }
- void MOUSE::setbeginxy(int X,int Y)
- {
- union REGS r;
- if(flag)
- {
- r.x.ax=4;
- r.x.cx=X;
- r.x.dx=Y;
- int86(0x33,&r,&r);
- x=X;y=Y;
- }
- }
- inline void MOUSE::message(void)
- {
- union REGS r;
- if(flag)
- {
- r.x.ax=3;
- int86(0x33,&r,&r);
- key=r.x.bx;
- KEYKEY=key;
- x=r.x.cx;
- y=r.x.dx;
- }}
- void MOUSE::mousekeymessage(void)
- {
- union REGS r;
- if(flag)
- {//-----按下-----
- //左键
- r.x.ax=5;
- r.x.bx=0;
- int86(0x33,&r,&r);
- key=KEYKEY=r.x.ax;
- leftnum=r.x.bx;
- lbx=r.x.cx;
- lby=r.x.dx;
- //右键
- r.x.ax=5;
- r.x.bx=1;
- int86(0x33,&r,&r);
- key=KEYKEY=r.x.ax;
- rightnum=r.x.bx;
- rbx=r.x.cx;
- rby=r.x.dx;
- //-----松开-----
- //左键
- r.x.ax=6;
- r.x.bx=0;
- int86(0x33,&r,&r);
- key=KEYKEY=r.x.ax;
- lex=r.x.cx;
- ley=r.x.dx;
- //右键
- r.x.ax=6;
- r.x.bx=1;
- int86(0x33,&r,&r);
- key=KEYKEY=r.x.ax;
- rex=r.x.cx;
- rey=r.x.dx;
- }}
- void MOUSE::show_mousekeymessage(void)
- {
- gotoxy(10,6);
- cout<<"Left ("<<lbx<<","<<lby<<")-("<<lex<<","<<ley<<")\n";
- gotoxy(10,7);
- cout<<"Right ("<<rbx<<","<<rby<<")-("<<rex<<","<<rey<<")\n";
- }
- void MOUSE::setmax(int x1,int x2)
- {
- union REGS r;
- if(flag)
- {
- if(!FLAG)
- {
- x1=(x1*winxsize)-winxsize;
- x2=(x2*winxsize)-winxsize;
- }
- r.x.ax=7;
- r.x.cx=x1;
- r.x.dx=x2;
- int86(0x33,&r,&r);
- }
- }
- void MOUSE::setmay(int y1,int y2)
- {
- union REGS r;
- if(flag)
- {
- if(!FLAG)
- {
- y1=(y1*winysize)-winysize;
- y2=(y2*winysize)-winysize;
- }
- r.x.ax=8;
- r.x.cx=y1;
- r.x.dx=y2;
- int86(0x33,&r,&r);
- }
- }
- void MOUSE::setmaxy(int x1,int y1,int x2,int y2)
- {
- union REGS r;
- if(flag)
- {
- r.x.ax=16;
- r.x.cx=x1;
- r.x.dx=y1;
- r.x.si=x2;
- r.x.di=y2;
- int86(0x33,&r,&r);
- }
- else hide();
- }
- inline int MOUSE::mousekey()
- {
- if(kbhit())return KEY();
- message();
- if(key==1) return(1001);
- if(key==2) return(1002);
- if(key==3) return(1003);
- return(-1);
- }
- void MOUSE::mousev()
- {
- if(flag)
- {
- _BX=20;
- _CX=20;
- _AX=0x1a;
- geninterrupt(0x33);
- }}
- int MOUSE::yesno(int bx,int by,int ex,int ey)
- { int t;
- if(bx>ex){t=bx;bx=ex;ex=t;}
- if(by>ey){t=by;by=ey;ey=t;}
- message();
- if(x>bx&&x<ex&&y>by&&y<ey)return 1;
- else return 0;
- }
- void MOUSE::run(void far interrupt(*p)(),int nn)
- {
- if(flag)
- {
- _ES=FP_SEG(p);
- _DX=FP_OFF(p);
- _CX=nn;
- _AX=0x14;
- geninterrupt(0x33);
- }
- }
- void MOUSE::close(void)
- {
- if(flag)
- {
- _ES=0;
- _DX=0;
- _CX=0;
- _AX=0x14;
- geninterrupt(0x33);
- }
- }
- //------------------------------------------------------------------------//
好了,先放这些吧。现在想想如果用DOS做简单的图形界面的嵌入式系统,也许这个也有点用(我刚到公司,做的第一个程序就是用这个改进的(DOS下的物料计量系统))
本文出自 “叶帆工作室” 博客,转载请与作者联系!