-->

program to detect click of button of mouse

using turboc++
-----------------------------------------------------------------------------------------------------
//program to detect button on click
#include <dos.h>
#include<stdio.h>
#include<conio.h>
union REGS in_put, out_put;// input and output variables stored in union
  //input for signal detection;output for screen display
void mouse_detected ()
{
in_put.x.ax = 0;// ax is register used for mouse
int86 (0X33,&in_put,&out_put);   //invokes interrupt using 0X33; for mouse, it is 0X33
if (out_put.x.ax == 0)    //condition testing
printf("\nMouse Failed To Initialize");
else
printf ("\nMouse was Succesfully Initialized");
       //initialization on screen
}
void show_mouse()
{
 in_put.x.ax = 1;   //1 is to display mouse
 int86(0X33,&in_put,&out_put); //interrupt invoked
}
void mouse_bttn()
{
while(!kbhit())    //until a keystroke is pressed
{
int x,y;
in_put.x.ax=3;    //3 is for co-ordinate value
 int86 (0X33,&in_put,&out_put);

 if (out_put.x.bx == 1)     //1 for left click
   printf ("\nLeft clicked");

 else if (out_put.x.bx == 2) //2 for right click
   printf ("\nRight clicked");
 else if (out_put.x.bx == 3)//3 for wheel click
   printf ("\nMiddle clicked");
   delay (200); // Otherwise due to quick computer response 100s of words will get print
}
}
int main ()
{
mouse_detected ();//calling of function
show_mouse();//calling of function
mouse_bttn();
getch ();
return 0;
}


Program to show pointer of mouse(text and graphics mode)

using turboc++
-----------------------------------------------------------------
//program to activate/detection mouse
#include <dos.h>
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
union REGS in_put, out_put;// input and output variables stored in union
  //input for signal detection;output for screen display
void showmouse()

{
 //in_put.x.ax = 1;// taking value 1 for display of mouse on screen  in text mode
 //int86 (0X33,&in_put,&out_put);//invoking interrupt
 //if we want to display mouse in graphics mode then
 //we put following code
 int gdriver=DETECT,gmode;  //graphics detection
 initgraph(&gdriver,&gmode,"c:\\tc\\bgi"); //graphics initialization
 in_put.x.ax = 1;// ax is register used for mouse .1 is used to display mouse
 int86 (0X33,&in_put,&out_put);   //invokes interrupt using 0X33; for mouse, it is 0X33
 getch();
 closegraph();   //graphics closing.
}
int main ()
{

showmouse();//calling of function
getch ();
return 0;
}

//note:If you want to use mouse in text mode, uncomment the commented lines
//in showmouse() function.
//we can also put mouse initialization part here.

program to activate /initialize mouse.

using turboc++
-------------------------------------------------
//program to activate/detection mouse
#include <dos.h>
#include<stdio.h>
#include<conio.h>
union REGS in_put, out_put;// input and output variables stored in union
  //input for signal detection;output for screen display
void mouse_detected ()
{
in_put.x.ax = 0;// ax is register used for mouse; 'x' is member of reg.
int86 (0X33,&in_put,&out_put);   //invokes interrupt using 0X33; for mouse, it is 0X33
if (out_put.x.ax == 0)    //condition testing
printf("\nMouse Failed To Initialize");
else
printf ("\nMouse was Succesfully Initialized");
       //initialization on screen
}
int main ()
{
mouse_detected ();//calling of function
getch ();
return 0;
}


program to move a circle.

using turboc++
--------------------------------------------------------------------------
//moving a circle
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
clrscr();
int gdriver, gmode;    //variables declaration
gdriver=DETECT;        // detection of graphics driver
int move_location=20; //first location for circle to start
initgraph(&gdriver, &gmode, "c:\\tc\\BGI");
while(!kbhit()) //Checks for currently available keystrokes
{
circle(move_location,210,70);//draws circle
setcolor(BLUE);   //sets the color blue of circle
delay(100);       //delays of 1/10th of second
cleardevice();    //clears the previous screen/graphics
move_location++;
if(move_location>=600)
{
move_location=0;   //repeating the motion.
cleardevice();  //clears the graphics screen
}
}
getch();          //gets one character from user and closes the graphics.
closegraph();     //closes graphics.h
}

Program to draw triangle.

using turboc++
------------------------------------------------------------------------
//drawing triangle
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
clrscr();
int gdriver, gmode;    //variables declaration
gdriver=DETECT;        // detection of graphics driver

initgraph(&gdriver, &gmode, "c:\\tc\\BGI");
line(300,100,300,200);//draws frist line
line(300,200,350,200);//draws second line
line(300,100,350,200);//draws third line

getch();          //gets one character from user and closes the graphics.
closegraph();     //closes graphics.h
}

Program to draw a a line.

using turboc++
--------------------------------------------------------------------------------------------
//drawing triangle
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
clrscr();
int gdriver, gmode;    //variables declaration
gdriver=DETECT;        // detection of graphics driver

initgraph(&gdriver, &gmode, "c:\\tc\\BGI");
line(500,100,300,200);//draws line of two co-ordinates .

getch();          //gets one character from user and closes the graphics.
closegraph();     //closes graphics.h
}

program to display a text with background colour.

using turbo c++
--------------------------------------------------------------------------------------
//program to set background color.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
clrscr();
int gdriver = DETECT, gmode;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
setbkcolor(BLUE);       //sets background color blue
printf("hello\n");      //prints hello
printf("how r u?");
getch();
closegraph();
}