You are here

C program to restrict mouse pointer

This program restricts mouse pointer in a rectangle. When this program is executed the mouse pointer is restricted in a rectangle i.e. you can't move mouse pointer out of the rectangle.

/* Program to restrict mouse-pointer */

C programming code

  1. #include<dos.h>
  2. #include<graphics.h>
  3. #include<conio.h>
  4.  
  5. int initmouse();
  6. void showmouseptr();
  7. void hidemouseptr();
  8. void restrictmouseptr(int, int, int, int);
  9.  
  10. union REGS i, o;
  11.  
  12. main()
  13. {
  14.    int status, gd = DETECT, gm;
  15.  
  16.    initgraph(&gd,&gm,"C:\\TC\\BGI");
  17.    settextstyle(DEFAULT_FONT,0,2);
  18.  
  19.    status = initmouse();
  20.  
  21.    if ( status == 0 )
  22.       outtext("Mouse support not available.\n");
  23.    else
  24.    {
  25.       showmouseptr();
  26.       rectangle(120,70,520,410);
  27.       restrictmouseptr(120,70,520,410);
  28.    }
  29.  
  30.    getch();
  31.    return 0;
  32. }
  33.  
  34. int initmouse()
  35. {
  36.    i.x.ax = 0;
  37.    int86(0X33, &i, &o);
  38.    return ( o.x.ax );
  39. }
  40.  
  41. void showmouseptr()
  42. {
  43.    i.x.ax = 1;
  44.    int86(0X33, &i, &o);
  45. }
  46.  
  47. void restrictmouseptr(int x1, int y1, int x2, int y2)
  48. {
  49.    i.x.ax = 7;
  50.    i.x.cx = x1;
  51.    i.x.dx = x2;
  52.    int86(0X33, &i, &o);
  53.  
  54.    i.x.ax = 8;
  55.    i.x.cx = y1;
  56.    i.x.dx = y2;
  57.    int86(0X33, &i, &o);
  58. }