You are here

Mouse Programs

C program to restrict mouse pointer in a circle

C program to restrict mouse pointer in a circle, i.e, you can't move it out of the circle. When you try to bring it outside of the circle, it is moved to its previous location which was inside the circle.

C programming code

#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 showmouseptr()
{
   i.x.ax = 1;
   int86(0X33, &i, &o);
}

C program to determine which mouse button is clicked

This program print which mouse button is clicked whether left or right, coordinates of the point where button is clicked are also printed on the screen.
/* Program to determine which mouse button is clicked */

C programming code

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

union REGS i, o;

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 getmousepos(int *button, int *x, int *y)
{
   i.x.ax = 3;
   int86(0X33, &i, &o);

   *button = o.x.bx;

C program to get current position of mouse pointer

This program prints the x and y coordinates of current position of mouse pointer i.e. wherever you move the mouse coordinates of that point will be printed on the screen.
/* Program to get mouse-pointer coordinates - where is the mouse */

C programming code

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

int initmouse();
void showmouseptr();
void hidemouseptr();
void getmousepos(int*,int*,int*);

union REGS i, o;

main()
{
   int gd = DETECT, gm, status, button, x, y, tempx, tempy;
   char array[50];

C program to display mouse pointer in graphics mode

This program displays mouse pointer in graphics mode. First graphics mode is initialized and then mouse using initmouse.

C programming code

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

int initmouse();
void showmouseptr();

union REGS i, o;

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

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

   status = initmouse();

   if ( status == 0 )
      printf("Mouse support not available.\n");
   else
      showmouseptr();

   getch();
   return 0;
}

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

C program to check if mouse support is available or not

/* Program to check if mouse driver is loaded or not */

C programming code

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

int initmouse();

union REGS i, o;

main()
{
   int status;

   status = initmouse();

   if ( status == 0 )
      printf("Mouse support not available.\n");
   else
      printf("Mouse support available.\n");

   getch();
   return 0;
}

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

Subscribe to RSS - Mouse Programs