You are on page 1of 11

Mouse pointer program in c-graphics

Guided by: prof. Nitin birari

Created by: All I.T Student

Only Show mouse pointer in output screen using c


graphics
#include<conio.h>
#include<graphics.h>
#include<dos.h>
union REGS i,o;
void showmouseptr() {
i.x.ax=1;
int86(0x33,&i,&o);
}
Int main()
{
int gd=DETECT,gm,button,x,y;
initgraph(&gd,&gm,"c:\\tc\\bgi");
showmouseptr();
getch();
return 0;
}

Output:

1|Page

Show mouse pointer and get position


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

union REGS i,o;


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;
}
Int main()
{
int gd=DETECT,gm,button,x,y;

//gd=DETECT or gd=0

initgraph(&gd,&gm,"c:\\tc\\bgi");
showmouseptr();
while(!kbhit())
{
getmousepos(&button,&x,&y);
if(button==1)

//Only left key use or mouse touch use

{
2|Page

button= -1;
printf("X=%d y=%d",x,y);
}
}
getch();
return 0;
}
Output:

3|Page

Show mouse pointer and get position using left and right
key of mouse
#include<conio.h>
#include<graphics.h>
#include<dos.h>

union REGS i,o;


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;
}
Int main()
{
int gd=DETECT,gm,button,x,y; //DETECT=0
initgraph(&gd,&gm,"c:\\tc\\bgi");
showmouseptr();
while(!kbhit())
{
getmousepos(&button,&x,&y);
4|Page

if(button==1) //Left key work of mouse pad


{
button=-1;
printf("X=%d y=%d",x,y);
}
else if(button==2) //Right key work of mouse pad
{
button=-1;
printf("Mayur X=%d y=%d",x,y);
}
}
getch();
return 0;
}
Output:

5|Page

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

union REGS i,o;


void showmouseptr()
{
i.x.ax=1;
int86(0x10,&i,&o); //only change 0x10
}
Int main()
{
int gd=DETECT,gm,button,x,y; // gd=DETECT or DETECT=0
initgraph(&gd,&gm,"c:\\tc\\bgi");
showmouseptr();
getch();
return 0;
}
Output:

6|Page

Show mouse pointer with current position


#include<conio.h>
#include<graphics.h>
#include<dos.h>
union REGS i,o;
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;
}
Int main()
{
int gd=DETECT,gm,button,x,y; //DETECT=0
char array[100];
initgraph(&gd,&gm,"c:\\tc\\bgi");
showmouseptr();
while(!kbhit())
{
getmousepos(&button,&x,&y);
if(button==1)

//Left click (if button==1 so work as left key)

{
button=-1;
7|Page

sprintf(array," X=%d y=%d",x,y); //store output in buffer


cleardevice(); //Clear screen
outtextxy(x,y,array); //x and y of value print with mouse pointer
}
if(button==2) //Right click (if button==2 so work as Right key)
{
button=-1;
sprintf(array," X=%d y=%d",x,y); //store output in buffer
cleardevice(); //Clear screen
outtextxy(x,y,array);

//x and y of value print with mouse pointer

}
}
getch();
return 0;
}

Output:

8|Page

How to Run time automatic snapshot take in c graphics


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<snap.h>
void main()
{
int gd= DETECT,gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
setcolor(YELLOW);
setfillstyle(2,2);
rectangle(0,0,200,200);
floodfill(100,100,YELLOW);
capture("C:\\TC\\snapshot\\Capture1.jpg");
getch();
}
Output:

9|Page

First TC or any place on make new folder. Suppose we make TC inside new folder name is snapshot.

Now program inside #include<snap.h> header file include.


After path set inside capture function.
i.e capture("C:\\TC\\snapshot\\Capture1.jpg");

First path set till our


folder

Here write photo name with


extension

Now captur.jpg image open then picture save in black and white.

10 | P a g e

You might also like