Home / C / C Program to restrict Mouse pointer in a Rectangle

C Program to restrict Mouse pointer in a Rectangle

This C Program will restrict the Mouse pointer Position in the Rectangle. The Mouse Programs are listed here if you want to learn more C Graphics Programs for Mouse.

Also If you want to learn how to restrict the Mouse Pointer in Circle then check here.

#include<dos.h>
#include<graphics.h>
#include<conio.h>

int initmouse();
void showmouseptr();
void hidemouseptr();
void restrictmouseptr(int, int, int, int);

union REGS i, o;

main()
{
   int status, gd = DETECT, gm;

   initgraph(&gd,&gm,"C:\\TC\\BGI");
   settextstyle(DEFAULT_FONT,0,2);

   status = initmouse();

   if ( status == 0 )
      outtext("Mouse support not available.\n");
   else
   {
      showmouseptr();
      rectangle(120,70,520,410);
      restrictmouseptr(120,70,520,410);
   }

   getch();
   return 0;
}

int initmouse()
{
   i.x.ax = 0;
   int86(0X33,&i,&o);
   return ( o.x.ax );
}

void showmouseptr()
{
   i.x.ax = 1;
   int86(0X33,&i,&o);
}

void restrictmouseptr(int x1, int y1, int x2, int y2)
{
   i.x.ax = 7;
   i.x.cx = x1;
   i.x.dx = x2;
   int86(0X33,&i,&o);

   i.x.ax = 8;
   i.x.cx = y1;
   i.x.dx = y2;
   int86(0X33,&i,&o);
}

 

Check Also

How to Solve Linear Equation in One Variable In C Programming?

C Program to Solve any Linear Equation in One Variable Find complete C program to ...

One comment

  1. Thanks Sir, Nice program. Can you please also post a program to detect right and left click from mouse.

Leave a Reply

Your email address will not be published. Required fields are marked *