voila c trés long mais ça vaut le coup ! la programmation est bien plus facile avec ça !
#include <dos.h>
#include <stdlib.h>
#include "msmouse.h"
const int MsCall = 0x33;
const int Iret = 0xcf;
const int False = 0;
const int True = 1;
MouseObject Mouse;
MouseObject::MouseObject(void)
{
OK = False;
MouseOff = True;
}
int MouseObject::DriverExists(void)
{
void far *address;
address = getvect(0x33);
return (address != NULL) && (*(unsigned char far *)address
!= Iret);
}
void MouseObject::Setup(VideoModeType VideoMode)
{
REGS regs;
OK = DriverExists();
if (OK)
{
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 == LowResGr) LowRes = True;
else LowRes = False;
if (VideoMode == HerculesGr) *(char far *)MK_FP(0x0040,0x0049) =
6;
OldX = 0; OldY = 0;
X = 0; Y = 0;
Dx = 0; Dy = 0;
Move(0,0);
}
int MouseObject::SetupOK(void)
{
return OK;
}
void MouseObject::Hide(void)
{
REGS regs;
if (!Operating()) return;
regs.x.ax = 2;
int86(MsCall, ®s, ®s);
}
void MouseObject::Show(void)
{
REGS regs;
if (!Operating()) return;
regs.x.ax = 1;
int86(MsCall, ®s, ®s);
}
unsigned MouseObject::Status(int &Mx, int &My)
{
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;
}
unsigned MouseObject::ButtonStatus(void)
{
int Mx, My;
if (!Operating()) return 0;
else return Status(Mx,My);
}
int MouseObject::PressCnt(unsigned ButtonMask)
{
REGS regs;
if (!Operating()) return 0;
regs.x.ax = 5;
regs.x.bx = ButtonMask >> 1;
int86(MsCall, ®s, ®s);
return regs.x.bx;
}
int MouseObject::ReleaseCnt(unsigned ButtonMask)
{
REGS regs;
if (!Operating()) return 0;
regs.x.ax = 6;
regs.x.bx = ButtonMask >> 1;
int86(MsCall, ®s, ®s);
return regs.x.bx;
}
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;
}
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;
}
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);
}
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);
}
void MouseObject::Move(int Mx, int My)
{
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);
}
void MouseObject::TurnOn(void)
{
if (OK && MouseOff)
{
MouseOff = False;
Show();
}
}
void MouseObject::TurnOff(void)
{
if(OK && !MouseOff)
{
Hide();
MouseOff = True;
}
}
int MouseObject::Operating(void)
{
return !MouseOff;
}
void MouseObject::SetGCursor(const MouseCursor&NewCursor)
{
REGS regs;
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, ®s, ®s, &sregs);
}