How to restrict Mouse Pointer in Circle using c Graphics Programming is given here.

#include<graphics.h> #include<conio.h> #include<dos.h> #include<stdlib.h> #include<math.h> union REGS i, o; int initmouse() { i.x.ax = 0; int86(0X33, &i, &o); return ( o.x.ax ); } void showmousepointer() { i.x.ax = 1; int86(0X33, &i, &o); } void hidemopusepointer() { i.x.ax = 2; int86(0X33,&i,&o); } void getmousepos(int *x, int *y) { i.x.ax = 3; int86(0X33, &i, &o); *x = o.x.cx; *y = o.x.dx; } void movemousepointer(int x, int y) { i.x.ax = 4; i.x.cx = x; i.x.dx = y; int86(0X33, &i, &o); } main() { int gd = DETECT, gm, midx, midy, radius, x, y, temp_x, temp_y; radius = 100; initgraph(&gd, &gm, "C:\\TC\\BGI"); if(!initmouse()) { closegraph(); exit(1); } midx = getmaxx()/2; midy = getmaxy()/2; showmousepointer(); movemousepointer(midx, midy); circle(midx, midy, radius); x = temp_x = midx; y = temp_y = midy; while(!kbhit()) { getmousepos(&x, &y); if((pow(x-midx,2)+pow(y-midy,2)-pow(radius,2))>0) { movemousepointer(temp_x, temp_y); x = temp_x; y = temp_y; } temp_x = x; temp_y = y; } closegraph(); return 0; }