Search This Blog


C program to restrict mouse pointer in a circle

Below is the C program to restrict mouse pointer in a circle. Here we have used below functions to achieve it.

int initmouse() : function is used to intialize the mouse pointer. Which returns int value. Value 0 indicates Mouse support is not available.

void showmousepointer() : function is used to show mouse pointer. Which does not return any value.

void getmouseposition(int *button, int *x, int *y) : function to get the position of check the position of the mouse pointer. Also it sets the 'button' variable value to 1 or 2, which identifies the which mouse button is clicked.

int kbhit() : Function is used to identify that is key is pressed or not.

void circle (int x,int y,int radius) : circle function is used to draw a circle with center (x, y).

Void closegraph() : Function is used to deallocate memory of graphics system.


union REGS i, o;

int initmouse()
{ = 0;
   int86(0X33, &i, &o);
   return ( );

void showmousepointer()
{ = 1;
   int86(0X33, &i, &o);

void hidemopusepointer()
{ = 2;

void getmouseposition(int *x, int *y)
{ = 3;
   int86(0X33, &i, &o);
   *x =;
   *y = o.x.dx;


void movemousepointer(int x, int y)
{ = 4; = x;
   i.x.dx = y;
   int86(0X33, &i, &o);

   int gd = DETECT, gm, midx, midy, radius, x, y, tempx, tempy;

   radius = 100;

   initgraph(&gd, &gm, "C:\\TC\\BGI");


   midx = getmaxx()/2;
   midy = getmaxy()/2;

   movemousepointer(midx, midy);
   circle(midx, midy, radius);

   x = tempx = midx;
   y = tempy = midy;

      getmouseposition(&x, &y);

         movemousepointer(tempx, tempy);
         x = tempx;
         y = tempy;

      tempx = x;
      tempy = y;

   return 0;

No comments:

Post a Comment