Tuesday 18 June 2013

MOUSE in C++

This is a simple program made in C/C++ to :
  • Initialize Mouse
  • Show mouse
  • Read Mouse Position
  • Detect Mouse Clicks (Left / Right) 

DOWNLOAD CPP / SOURCE CODE



/*  Program Starts Here */
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<process.h>

void MouseMenu();
void main()
{
     MouseMenu();

}

///////////////////////////////////////
///////////////////////////////////////

void MouseMenu()
{
int i,j,k,l;
clrscr();_setcursortype(_NOCURSOR);
textmode(C80);textcolor(14);
for(i=1;i<=4;i++){gotoxy(35,5*i);cprintf("%c",201);gotoxy(45,5*i);cprintf("%c",187);
gotoxy(36,5*i);cprintf("%c%c%c%c%c%c%c%c%c",205,205,205,205,205,205,205,205,205);
gotoxy(36,5*i+3);cprintf("%c%c%c%c%c%c%c%c%c",205,205,205,205,205,205,205,205,205);
gotoxy(35,5*i+3);cprintf("%c",200);gotoxy(45,5*i+3);cprintf("%c",188);
gotoxy(35,5*i+1);cprintf("%c",186);gotoxy(45,5*i+1);cprintf("%c",186);
gotoxy(35,5*i+2);cprintf("%c",186);gotoxy(45,5*i+2);cprintf("%c",186);
      }
textcolor(13);
gotoxy(37,6);cprintf("MENU 1");
gotoxy(37,11);cprintf("MENU 2");
gotoxy(37,16);cprintf("MENU 3");
gotoxy(37,21);cprintf("MENU 4");
textcolor(12);
gotoxy(38,7);cprintf("JAVA");
gotoxy(38,12);cprintf("C++");
gotoxy(38,17);cprintf("PHP");
gotoxy(37,22);cprintf("ANDROID");
_setcursortype(_NOCURSOR);
REGS regs;
//Initializing mouse
regs.x.ax=0;int86(0x33,&regs,&regs);
//Showing mouse
regs.x.ax=1;int86(0x33,&regs,&regs);

/* Reading current position of mouse */
   while(1){
   regs.x.ax=3;int86(0x33,&regs,&regs);
  if(regs.x.cx>=270&&regs.x.cx<=365&&regs.x.dx>=32&&regs.x.dx<=63)
  {
   textcolor(14);
   gotoxy(37,6);cprintf("MENU 1");
   textcolor(14);
   gotoxy(38,7);cprintf("JAVA");
   //Reading mouse click
if(regs.x.bx==1){
   gotoxy(2,2);textcolor(2);
   cprintf("Left Button Clicked!");gotoxy(2,3);cprintf("Menu 1 Selected !");
   gotoxy(2,4);cprintf("JAVA !");
   }
if(regs.x.bx==2){
   gotoxy(2,2);textcolor(2);
   cprintf("Right Button Clicked!");gotoxy(2,3);cprintf("Menu 1 Selected !");
   gotoxy(2,4);cprintf("JAVA !");
   }
       while(kbhit()){exit(0);}
  }
  else{textcolor(13);
   gotoxy(37,6);cprintf("MENU 1");
   textcolor(12);
   gotoxy(38,7);cprintf("JAVA");
      }

   ////////////////////////////////////////

   if(regs.x.cx>=270&&regs.x.cx<=365&&regs.x.dx>=70&&regs.x.dx<=101)
  {
   textcolor(14);
   gotoxy(37,11);cprintf("MENU 2");
   textcolor(14);
   gotoxy(38,12);cprintf("C++");
   //Reading mouse click
if(regs.x.bx==1){
   gotoxy(2,2);textcolor(2);
   cprintf("Left Button Clicked!"); gotoxy(2,3);cprintf("Menu 2 Selected !");
   gotoxy(2,4);cprintf("C++ !");
   }
if(regs.x.bx==2){
   gotoxy(2,2);textcolor(2);
   cprintf("Right Button Clicked!");gotoxy(2,3);cprintf("Menu 2 Selected !");
   gotoxy(2,4);cprintf("C++ !");
   }
       while(kbhit()){exit(0);}
  }
  else{textcolor(13);
   gotoxy(37,11);cprintf("MENU 2");
   textcolor(12);
   gotoxy(38,12);cprintf("C++");
      }

      //////////////////////////////////////

      if(regs.x.cx>=270&&regs.x.cx<=365&&regs.x.dx>=110&&regs.x.dx<=141)
  {
   textcolor(14);
   gotoxy(37,16);cprintf("MENU 3");
   textcolor(14);
   gotoxy(38,17);cprintf("PHP");
   //Reading mouse click
if(regs.x.bx==1){
   gotoxy(2,2);textcolor(2);
   cprintf("Left Button Clicked!"); gotoxy(2,3);cprintf("Menu 3 Selected !");
   gotoxy(2,4);cprintf("PHP !");
   }
if(regs.x.bx==2){
   gotoxy(2,2);textcolor(2);
   cprintf("Right Button Clicked!");gotoxy(2,3);cprintf("Menu 3 Selected !");
   gotoxy(2,4);cprintf("PHP !");
   }
       while(kbhit()){exit(0);}
  }
  else{textcolor(13);
   gotoxy(37,16);cprintf("MENU 3");
   textcolor(12);
   gotoxy(38,17);cprintf("PHP");
      }

      /////////////////////////////////////
     if(regs.x.cx>=270&&regs.x.cx<=365&&regs.x.dx>=150&&regs.x.dx<=182)
  {
   textcolor(14);
   gotoxy(37,21);cprintf("MENU 4");
   textcolor(14);
   gotoxy(37,22);cprintf("ANDROID");
   //Reading mouse click
if(regs.x.bx==1){
   gotoxy(2,2);textcolor(2);
   cprintf("Left Button Clicked!"); gotoxy(2,3);cprintf("Menu 4 Selected !");
   gotoxy(2,4);cprintf("ANDROID !");
   }
if(regs.x.bx==2){
   gotoxy(2,2);textcolor(2);
   cprintf("Right Button Clicked!");gotoxy(2,3);cprintf("Menu 4 Selected !");
   gotoxy(2,4);cprintf("ANDROID !");
   }
       while(kbhit()){exit(0);}
  }
  else{textcolor(13);
   gotoxy(37,21);cprintf("MENU 4");
   textcolor(12);
   gotoxy(37,22);cprintf("ANDROID");
      }
while(kbhit()){exit(0);}
  }
}
/* Codetechie.blogspot.com */
/* END */

Download Source Code (CPP)

0 comments: