/*
MOUSE.INC
*/
void pascal set_event_handler(int call_mask,void far( *location)())
{
union REGS r;
struct SREGS sr;
if(MOUSE_THERE){ /* THE MOUSE FUNCTION 12 */
r.x.ax=12;
r.x.cx=call_mask;
r.x.dx=FP_OFF( location );
sr.es=FP_SEG( location );
int86x(0x33,&r,&r,&sr);
}
}
/*---------------------------------------------------------------------*/
void near event_processor(int event_status,int button_status,int x,int y)
/* LOAD THE MOUSE EVENT PROGRAGM */
{
if(MOUSE_THERE){
if( (CMX!=x) || (CMY!=y) ){
MOUSE_MOVED=1;
CMX=x; CMY=y;
}
else
MOUSE_MOVED=0;
BSTATE=button_status;
if(event_status & 2){ LBUTTON_DOWN=1; LBUTTON_UP=0; }
if(event_status & 8){ RBUTTON_DOWN=1; RBUTTON_UP=0; }
if(event_status & 4){ LBUTTON_UP=1; LBUTTON_DOWN=0; }
if(event_status & 16){ RBUTTON_UP=1; RBUTTON_DOWN=0; }
}
}
/*--------------------------------------------------------------------*/
int reset_mouse(void) /* THE MOUSE FUNCTION 0 */
{
_AX=0;
geninterrupt(0x33);
if(_AX>0){
MOUSENUM=_AX;
MOUSE_THERE=1;
mouse_on();
return(OK);
}
else{
MOUSE_THERE=0;
return(ERROR);
}
}
/*-------------------------------------------------------------------*/
void mouse_off(void) /* THE MOUSE FUNCTION 2 */
{
if( !MOUSE_THERE || MOUSE_VISIBLE==0 ) return;
_AX=2;
geninterrupt(0x33);
MOUSE_VISIBLE=0;
}
/*-------------------------------------------------------------------*/
void mouse_on(void) /* THE MOUSE FUNCTION 1 */
{
if( !MOUSE_THERE || MOUSE_VISIBLE==1 ) return;
_AX=1;
geninterrupt(0x33);
MOUSE_VISIBLE=1;
}
/*-------------------------------------------------------------------*/
void mouse_shape(int shape[32],int hotx,int hoty)
{
union REGS regs;
struct SREGS sregs;
mouse_off();
regs.x.ax=9;
regs.x.bx=hotx;
regs.x.cx=hoty;
regs.x.dx=FP_OFF(shape);
sregs.es=FP_SEG(shape);
int86x(0x33,®s,®s,&sregs);
mouse_on();
}
/*------------------------------------------------------------------*/
void set_mouse_position(int x,int y)
{
_AX=4;
_CX=x;
_DX=y;
geninterrupt(0x33);
}
/*-------------------------------------------------------------------*/
/*
调用双击的条件为判断是否为左键下
当调用双击不成时,再检查一次左键按下否,如下,{则说明刚才为单击,将左键状态消去}
即:每次调用双击后,必须再调用一次单击,否则有可能丢失键击状态
if( LBUTTON_DOWN ){
if( get_double_press() ) ... 双击如何
else ...单击如何
}
*/
int get_double_press(void); /* get if lbutton was pressed twice */
int get_double_press(void)
{
int x,y;
if( LBUTTON_DOWN ){
LBUTTON_DOWN=0;
x=CMX; y=CMY;
Delay(DOUBLE_CLICK_TIME);
if(LBUTTON_DOWN && x==CMX && y==CMY){
LBUTTON_DOWN=0;
LBUTTON_UP=0;
return(1);
}
else{
LBUTTON_DOWN=1;
return(0);
}
}
}
/*--------------------------------------------------------------------*/
void set_text_cursor(int groundmask,int textmask)
{
_AX=10;
_BX=0;
_CX=groundmask;
_DX=textmask;
geninterrupt(0x33);
}
/*--------------------------------------------------------------------*/
void InstallEvent(void)
{
set_event_handler(127,event_handler);
}
/*-----------------------------------------------------------*/
void reset_event_status(void)
{
MOUSE_MOVED=0; LBUTTON_DOWN=0;
RBUTTON_DOWN=0; LBUTTON_UP=0;
RBUTTON_UP=0; BSTATE=0;
}
/*------------------------------------------------------------------------*/
void set_mousex(int minx,int maxx)
{
_AX=7;
_CX=minx; _DX=maxx;
geninterrupt(0x33);
}
/*-----------------------------------------------------------------------*/
void set_mousey(int miny,int maxy)
{
_AX=8;
_CX=miny; _DX=maxy;
geninterrupt(0x33);
}
本文地址:http://com.8s8s.com/it/it25141.htm