Wednesday, September 19, 2012

Code#104:c program to determine which mouse button is clicked

| |
Basic C Language Program to determine which mouse button is clicked   is explained below with a detailed explanation,you will find it easy to go through this program, Sample input and output screen shots has been provide for the better understandability to the user, leave a comment if you are satisfied with the code
                                                      Click Read more for the 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;
   *x = o.x.cx;
   *y = o.x.dx;
}

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

   initgraph(&gd,&gm,"C:\\TC\\BGI");
   settextstyle(DEFAULT_FONT,0,2);

   status = initmouse();

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

      getmousepos(&button,&x,&y);

      while(!kbhit())
      {
         getmousepos(&button,&x,&y);

         if( button == 1 )
         {
            button = -1;
            cleardevice();
            sprintf(array,"Left Button clicked x = %d y = %d",x,y);
            outtext(array);
         }
         else if( button == 2 )
         {
            button = -1;
            cleardevice();
            sprintf(array,"Right Button clicked x = %d y = %d",x,y);
            outtext(array);
         }

      }
   }

   getch();
   return 0;
}

0 comments:

Post a Comment

Powered by Blogger.