#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define NOT_INSTALLED 2
#define TWO_BUTTON 3
#define NOT_TWO_BUTTON 4
#define OTHER 5
#define SHOW 2
#define LB_PRESS 1
int InitMouse (void);
void ShowMouse (int);
void ExitProg (int);
int GetStatus (unsigned int &, unsigned int &);
void main (void)
{
int status;
unsigned int x, y;
clrscr();
status = InitMouse ();
if (status == NOT_INSTALLED)
ExitProg (1);
ShowMouse (SHOW);
printf ("Push left button to end...\n");
while (GetStatus (x, y) != LB_PRESS)
{
gotoxy(10, 10);
printf("x = %3d, y = %3d", x, y);
}
gotoxy(1, 12);
printf ("Left button pushed !\n");
ExitProg (0);
}
int InitMouse (void)
{
asm {
mov ax,0021h
int 33h
}
if (_AX != 0xffff)
{
// 0xffff => mouse driver installed
printf ("Mouse driver not installed!\n");
return NOT_INSTALLED;
}
else if (_BX == 0xffff)
{
// 0xffff => 2 button mouse
printf ("Normal mouse with 2 buttons installed.\n");
return TWO_BUTTON;
}
else if (_BX == 0x0000)
{
printf ("Mouse with more/less than 2 buttons installed.\n");
return NOT_TWO_BUTTON;
}
printf ("Non standard mouse installed.\n");
return OTHER;
}
void ShowMouse (int show)
{
if (show == SHOW)
asm mov ax,0001h // show mouse
else
asm mov ax,0002h // hide mouse
asm int 33h
}
int GetStatus (unsigned int &xpos, unsigned int &ypos)
{
asm {
mov ax,0003h
int 33h
}
xpos = _CX;
ypos = _DX;
if (_BX & 0x0001) // '0' bit indicates LB status
return LB_PRESS;
else
return 0;
}
void ExitProg (int retval)
{
printf ("Press a key to return to system\n");
getch ();
exit (retval);
}