发信人: xiaomiao(一笛风)
整理人: wenbobo(2002-09-18 10:14:29), 站内信件
|
【 在 moonsoftware 的大作中提到:】
:谢谢,请发给我
:[email protected]
:[email protected]
:万分感谢!
:
:
:......
/* the mouse function subroutines and defines */
/* filename :MSMOUSE.H */
struct HotSpotStruct{ int X,Y;};
struct MouseCursor{
HotSpotStruct HotSpot;
unsigned ScreenMask[16];
unsigned CursorMask[16];
};
extern const MouseCursor ArrowCursor;
extern const MouseCursor HandCursor;
extern const MouseCursor LeftRightCursor;
extern const MouseCursor UpDownCursor;
// mouse event code
const unsigned Idle=0x0000;
const unsigned MouseDown=0xff01;
const unsigned LMouseDown=0xff01;
const unsigned RMouseDown=0xff02;
const unsigned MouseStillDown=0xff04;
const unsigned LMouseStillDown=0xff04;
const unsigned RMouseStillDown=0xff08;
const unsigned MouseUp=0xff10;
const unsigned LMouseUp=0xff10;
const unsigned RMouseUp=0xff20;
const unsigned MouseEnter=0xff40;
const unsigned MouseLeave=0xff80;
const unsigned MouseWithin=0xffc0;
const unsigned LeftButton=0x0001;
const unsigned RightButton=0x0002;
// the video mode that the mouse is running under
enum VideoModeType{TextScrn,LowResScr,HerculesGr,Graphics};
class MouseObject{
protected:
int Oldx,Oldy;
char OK;
char MouseOff;
char LowRes;
char TextMode;
public:
int X,Y,Dx,Dy;
MouseObject(void);
void Setup(VideoModeType VideoMode);
int DriverExists(void);
int SetupOK(void);
void Hide(void);
void Show(void);
unsigned Status(int &Mx,int &My);
unsigned ButtonStatus(void);
int PressCnt(unsigned ButtonMask);
int ReleaseCnt(unsigned ButtonMask);
unsigned Event(int &Mx,int &My);
unsigned WaitForAnyEvent(int &Mx,int &My);
void WaitForEvent(unsigned E,int &Mx,int &My);
int Moved(void);
void Move(int Mx,int My);
void TurnOn(void);
void TurnOff(void);
int Operating(void);
void SetCursor(const MouseCursor &NewCursor);
};
extern MouseObject Mouse;
/* FileName: MSMOUSE.CPP */
/* Microsoft Mouse Subroutines Written in C++ */
#include <dos.h>
#include <stdio.h>
const int MsCall=0x33; // INT 33H
const int Iret=0xcf;
const int False=0;
const int True=1;
/* constructor */
MouseObject::MouseObject(void)
{
OK=False;
MouseOff=True;
}
/* detect the mouse driver */
int MouseObject::DriverExists(void)
{
void far *address;
address=getvect(MsCall);
return (address!=NULL)&&(*(unsigned char far*)address!=Iret);
}
/* initialize the mouse */
void MouseObject::Setup(VideoModeType VideoMode)
{
union REGS regs;
OK=DriverExists();
if(OK)
{
if(VideoMode==HerculesGr) *(char far*)MK_FP(0x0040,0x0049)=6;
regs.x.ax=0;
int86(MsCall,®s,®s);
if(regs.x.ax==0) OK=False;
}
if(!OK)
{
TurnOff();
return;
}
TurnOn();
if(VideoMode==TextScrn)
TextMode=True;
else
TextMode=False;
if(VideoMode==TextScrn)
LowRes=True;
else
LowRes=False;
Oldx=0;
Oldy=0;
X=0;
Y=0;
Dx=0;
Dy=0;
Move(0,0);
}
int MouseObject::SetupOK(void)
{
return OK;
}
/* close the cursor */
void MouseObject::Hide(void)
{
union REGS regs;
if(!Operating())
return;
regs.x.ax=2;
int86(MsCall,®s,®s);
}
/* show the cursor */
void MouseObject::Show(void)
{
union REGS regs;
if(!Operating())
return;
regs.x.ax=1;
int86(MsCall,®s,®s);
}
/* get the mouse status */
unsigned MouseObject::Status(int &Mx,int &My)
{
union REGS regs;
if(!Operating())
{ Mx=0; My=0;
return 0;
}
regs.x.ax=3;
int86(MsCall,®s,®s);
Mx=regs.x.cx;
My=regs.x.dx;
if(TextMode)
{
Mx>>=3;
My>>=3;
}
if(LowRes) Mx>>=1;
return regs.x.bx;
}
/* get the button status */
unsigned MouseObject::ButtonStatus(void)
{
int Mx,My;
if(!Operating())
return 0;
else
return Status(Mx,My);
}
/* Get the press count */
int MouseObject::PressCnt(unsigned ButtonMask)
{
union REGS regs;
if(!Operating())
return 0;
regs.x.ax=5;
regs.x.bx=ButtonMask>>1;
int86(MsCall,®s,®s);
return regs.x.bx;
}
/* Get the Release count */
int MouseObject::ReleaseCnt(unsigned ButtonMask)
{
union REGS regs;
if(!Operating())
return 0;
regs.x.ax=6;
regs.x.bx=ButtonMask>>1;
int86(MsCall,®s,®s);
return regs.x.bx;
}
/* The Mouse Event */
unsigned MouseObject::Event(int &Mx, int &My)
{
unsigned E;
if(!Operating())
{
Mx=0;
My=0;
return Idle;
}
E=Status(Mx,My);
if(E==0)
{
if(PressCnt(LeftButton)>0) E=LMouseDown;
else if(PressCnt(RightButton)>0) E=RMouseDown;
else if(ReleaseCnt(LeftButton)>0) E=LMouseUp;
else if(ReleaseCnt(RightButton)>0) E=RMouseUp;
}
else
{
if(E&LeftButton)
{
if(PressCnt(LeftButton)>0) E=LMouseDown;
else E=LMouseStillDown;
}
else if(PressCnt(RightButton)>0)
E=RMouseDown;
else
E=RMouseStillDown;
}
return E;
}
/* Wait for response */
unsigned MouseObject::WaitForAnyEvent(int &Mx,int &My)
{
unsigned E;
if(!Operating())
{
Mx=0;
My=0;
return Idle;
}
do{
E=Event(Mx,My);
} while(E==Idle);
return E;
}
/* Wait for some response */
void MouseObject::WaitForEvent(unsigned E,int &Mx,int &My)
{
unsigned Etry;
if(!Operating())
{
Mx=0;
My=0;
return ;
}
do{
Etry=Event(Mx,My);
} while(Etry!=E);
}
/* Move the cursor */
int MouseObject::Moved(void)
{
if(!Operating())
return False;
Oldx=X; Oldy=Y;
Status(X,Y);
Dx=X-Oldx;
Dy=Y-Oldy;
return (Dx!=0)||(Dy!=0);
}
/* Move the cursor to X,Y */
void MouseObject::Move(int Mx,int My)
{
union REGS regs;
if(!Operating()) return;
regs.x.ax=4;
regs.x.cx=Mx;
regs.x.dx=My;
if(TextMode)
{
regs.x.cx<<=3;
regs.x.dx<<=3;
}
if (LowRes) regs.x.cx<<=1;
int86(MsCall,®s,®s);
}
/* Turn on the cursor */
void MouseObject::TurnOn(void)
{
if(OK&&MouseOff)
{
MouseOff=False;
Show();
}
}
/* Turn off the cursor */
void MouseObject::TurnOff(void)
{
if(OK&&!MouseOff)
{
Hide();
MouseOff=True;
}
}
/* if it is operating */
int MouseObject::Operating(void)
{
return !MouseOff;
}
/* set the new mouse cursor */
void MouseObject::SetCursor(const MouseCursor &NewCursor)
{
union REGS regs;
struct SREGS sregs;
if(!Operating()) return;
regs.x.ax=9;
regs.x.bx=NewCursor.HotSpot.X;
regs.x.cx=NewCursor.HotSpot.Y;
regs.x.dx=FP_OFF(NewCursor.ScreenMask);
sregs.es=FP_SEG(NewCursor.ScreenMask);
int86x(MsCall,& regs,& regs,& sregs);
}
/* different mouse cursor types */
const MouseCursor ArrowCursor={
{0,0},
{ // Screen Mask
0x3fff,0x1fff,0x0fff,0x07ff,
0x03ff,0x01ff,0x00ff,0x007f,
0x003f,0x00ff,0x01ff,0x10ff,
0x30ff,0xf87f,0xf87f,0xfc3f},
{ // Cursor Mask
0x0000,0x4000,0x6000,0x7000,
0x7800,0x7c00,0x7e00,0x7f00,
0x7f80,0x7e00,0x7c00,0x4600,
0x0600,0x0300,0x0300,0x0180}
};
const MouseCursor HandCursor={
{4,0},
{ // Screen Mask
0xf3ff,0xe1ff,0xe1ff,0xe1ff,
0xe001,0xe000,0xe000,0xe000,
0x8000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x8001,0xc003},
{ // Cursor Mask
0x0c00,0x1200,0x1200,0x1200,
0x13fe,0x1249,0x1249,0x1249,
0x7249,0x9001,0x9001,0x9001,
0x8001,0x8001,0x4002,0x3ffc}
};
const MouseCursor LeftRightCursor={
{8,8},
{ // Screen Mask
0xffff,0xffff,0xfbdf,0xf3cf,
0xe3c7,0xc003,0x8001,0x0000,
0x8001,0xc003,0xe3c7,0xf3cf,
0xfbdf,0xffff,0xffff,0xffff},
{ // Cursor Mask
0x0000,0x0000,0x0420,0x0c30,
0x1428,0x27e4,0x4002,0x8001,
0x4002,0x27e4,0x1428,0x0c30,
0x0420,0x0000,0x0000,0x0000}
};
const MouseCursor UpDownCursor={
{8,8},
{ // Screen Mask
0xfeff,0xfcff,0xf83f,0xf01f,
0xe00f,0xc007,0xf83f,0xf83f,
0xf83f,0xf83f,0xc007,0xe00f,
0xf01f,0xf83f,0xfc7f,0xfeff},
{ // Cursor Mask
0x0100,0x0280,0x0440,0x0820,
0x1010,0x3c78,0x0440,0x0440,
0x0440,0x0440,0x3c78,0x1010,
0x0820,0x0440,0x0280,0x0100}
};
----
广州社区数据库技术
广州社区Unix
|
|