Home / C / Hide Mouse Pointer C Program

Hide Mouse Pointer C Program

How to Hide a Mouse Pointer Program in C : This program will show and hide the mouse pointer after each user input by a key stroke.

Illustration & Example: There are two functions used in the program-

  • showmousepointer(); -> To Show / display the pointerHide Mouse pointer
  • hidemousepointer(); -> to Hide / disappear the pointer

 

  1. Initialise the Graphics using a graphic driver variable.
  2. Then Check the Mouse Availability. Display error message if not available.
  3. After checking the Mouse use a While Loop to hide and show the Mouse pointer on user input / key stroke using Getch().

Hide/ Disappear Mouse Pointer Program

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

void showmousepointer();
void hidemousepointer();

union REGS i, o;

int main() {
   int count = 1, gDriver = DETECT, gMode;

   initgraph(&gDriver, &gMode, "C\\:tc\\bgi");

   i.x.ax = 0;
   int86(0X33, &i, &o);

   if (o.x.ax == 0) {
      printf("Mouse Support is Unavailable !!");
   } else {
      showmousepointer();

      while (count <= 10) // This while loop accepts 10 keystrokes or user inputs.
       {
         getch();
         count++;
         if (count % 2 == 0) // Mouse Pointer will be hidden on even values
            hidemousepointer();
         else
            showmousepointer(); // Mouse Pointer will be show on Odd Values
      }
   }
   getch();
   return 0;
}

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

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

This will check if the mouse driver exists or not.

InputOutputComment
ax=0x0000ax=0x0000 or 0xFFFF
bx=number of buttons
0x0000 installed
0xFFFF not installed

Int 33,0×01 : Show Mouse cursor

InputOutputComment
ax=0x0001none

Int 33,0×02 : Hide Mouse Cursor

InputOutputComment
ax=0x0002none

In and out register must be type of REGS. REGS is a built in UNION declaration in C. It is defined in the dos.h header file

Syntax :

Check Also

C Program to find the Largest Digit in the Number

Write a Program in C to find the Largest Digit in the number. This is a simple code ...

Leave a Reply

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

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.