C programm Examples
C Program to check if mouse support is available or not
#include
#include
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 );
}
C Program to display mouse pointer in textmode
#include
#include
int initmouse();
void showmouseptr();
union REGS i, o;
main()
{
int status;
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);
return ( o.x.ax );
}
void showmouseptr()
{
i.x.ax = 1;
int86(0X33,&i,&o);
}
C Program to display mouse pointer in graphics mode
#include
#include
#include
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);
return ( o.x.ax );
}
void showmouseptr()
{
i.x.ax = 1;
int86(0X33,&i,&o);
}
C Program to hide mouse pointer
#include
#include
#include
int initmouse();
void showmouseptr();
void hidemouseptr();
union REGS i, o;
main()
{
int status, count = 1, gd = DETECT, gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
status = initmouse();
if ( status == 0 )
printf("Mouse support not available.\n");
else
{
showmouseptr();
while(count
C Program to get current position of mouse pointer
#include
#include
#include
#include
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];
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);
tempx = x;
tempy = y;
while(!kbhit())
{
getmousepos(&button,&x,&y);
if( x == tempx && y == tempy )
{}
else
{
cleardevice();
sprintf(array,"X = %d, Y = %d",x,y);
outtext(array);
tempx = x;
tempy = y;
}
}
}
getch();
return 0;
}
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;
}
C program to determine which mouse button is clicked
#include
#include
#include
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;
}
C program to restrict mouse pointer
#include
#include
#include
int initmouse();
void showmouseptr();
void hidemouseptr();
void restrictmouseptr(int, int, int, int);
union REGS i, o;
main()
{
int status, gd = DETECT, gm;
initgraph(&gd,&gm,"C:\\TC\\BGI");
settextstyle(DEFAULT_FONT,0,2);
status = initmouse();
if ( status == 0 )
outtext("Mouse support not available.\n");
else
{
showmouseptr();
rectangle(120,70,520,410);
restrictmouseptr(120,70,520,410);
}
getch();
return 0;
}
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 restrictmouseptr(int x1, int y1, int x2, int y2)
{
i.x.ax = 7;
i.x.cx = x1;
i.x.dx = x2;
int86(0X33,&i,&o);
i.x.ax = 8;
i.x.cx = y1;
i.x.dx = y2;
int86(0X33,&i,&o);
}
C program to restrict mouse pointer in a circle
#include
#include
#include
#include
#include
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 hidemopuseptr()
{
i.x.ax = 2;
int86(0X33,&i,&o);
}
void getmousepos(int *x, int *y)
{
i.x.ax = 3;
int86(0X33, &i, &o);
*x = o.x.cx;
*y = o.x.dx;
}
void movemouseptr(int x, int y)
{
i.x.ax = 4;
i.x.cx = x;
i.x.dx = y;
int86(0X33, &i, &o);
}
main()
{
int gd = DETECT, gm, midx, midy, radius, x, y, tempx, tempy;
radius = 100;
initgraph(&gd, &gm, "C:\\TC\\BGI");
if(!initmouse())
{
closegraph();
exit(1);
}
midx = getmaxx()/2;
midy = getmaxy()/2;
showmouseptr();
movemouseptr(midx, midy);
circle(midx, midy, radius);
x = tempx = midx;
y = tempy = midy;
while(!kbhit())
{
getmousepos(&x, &y);
if((pow(x-midx,2)+pow(y-midy,2)-pow(radius,2))>0)
{
movemouseptr(tempx, tempy);
x = tempx;
y = tempy;
}
tempx = x;
tempy = y;
}
closegraph();
return 0;
}
Leave a Reply 88 views, 1 so far today |