c-gui-thunderbolt
  Sample Mouse Program
 
// Mouse C GUI Program

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<alloc.h>
union REGS i,o;
struct SREGS s;
unsigned int c[][32]={
0x07e0,0x07e0,0x07e0,0x07e0,0x03c0,0xf00f,0xf81f,0xf81f,0xf81f,
                0xf81f,0xf00f,0x03c0,0x07e0,0x07e0,0x07e0,0x07e0,
0x0000,0x700e,0x4002,0x500a,0x0810,0x0000,0x0240,0x0180,
                0x0180,0x0240,0x0000,0x0810,0x500a,0x4002,0x700e,0x0000,
 
0xffff,0x83c1,0x83c1,0x83c1,0x83c1,0x8001,0xf81f,0xf81f,0xf81f,
                0xf81f,0x8001,0x83c1,0x83c1,0x83c1,0x83c1,0xffff,
0x0000,0x0000,0x381c,0x300c,0x2814,0x0000,0x0240,0x0180,
                0x0180,0x0240,0x0000,0x2814,0x300c,0x381c,0x0000,0x0000,
 
0xffff,0xffff,0xc183,0xc183,0xc183,0xc003,0xc003,0xf81f,0xf81f,
                0xc003,0xc003,0xc183,0xc183,0xc183,0xffff,0xffff,
0x0000,0x0000,0x0000,0x1c38,0x1818,0x1008,0x0240,0x0180,
                0x0180,0x0240,0x1008,0x1818,0x1c38,0x0000,0x0000,0x0000,
 
0xffff,0xffff,0xffff,0xe007,0xe007,0xe007,0xe007,0xe007,0xe007,
                0xe007,0xe007,0xe007,0xe007,0xffff,0xffff,0xffff,
0x0000,0x0000,0x0000,0x0000,0x0e70,0x0810,0x0a50,0x0180,
                0x0180,0x0a50,0x0810,0x0e70,0x0000,0x0000,0x0000,0x0000,
 
0xffff,0xffff,0xffff,0xffff,0xf00f,0xf00f,0xf00f,0xf00f,0xf00f,0xf00f,
                0xf00f,0xf00f,0xffff,0xffff,0xffff,0xffff,
0x0000,0x0000,0x0000,0x0000,0x0000,0x07e0,0x0660,0x05a0,
                 0x05a0,0x0660,0x07e0,0x0000,0x0000,0x0000,0x0000,0x0000,
 
0xffff,0xffff,0xffff,0xe007,0xe007,0xe007,0xe007,0xe007,0xe007,
                0xe007,0xe007,0xe007,0xe007,0xffff,0xffff,0xffff,
0x0000,0x0000,0x0000,0x0000,0x0e70,0x0810,0x0a50,0x0180,
                0x0180,0x0a50,0x0810,0x0e70,0x0000,0x0000,0x0000,0x0000,
 
0xffff,0xffff,0xc183,0xc183,0xc183,0xc003,0xc003,0xf81f,0xf81f,0xc003,
                0xc003,0xc1c3,0xc183,0xc183,0xffff,0xffff,
0x0000,0x0000,0x0000,0x1c38,0x1818,0x1008,0x0240,0x0180,0x0180,
                0x0240,0x1008,0x1818,0x1c38,0x0000,0x0000,0x0000,
 
0xffff,0x83c1,0x83c1,0x83c1,0x83c1,0x8001,0xf81f,0xf81f,0xf81f,
                0xf81f,0x8001,0x83c1,0x83c1,0x83c1,0x83c1,0xffff,
0x0000,0x0000,0x381c,0x300c,0x2814,0x0000,0x0240,0x0180,
                 0x0180,0x0240,0x0000,0x2814,0x300c,0x381c,0x0000,0x0000,
 
0x07e0,0x07e0,0x07e0,0x07e0,0x03c0,0xf00f,0xf81f,0xf81f,0xf81f,
                0xf81f,0xf00f,0x03c0,0x07e0,0x07e0,0x07e0,0x07e0,
0x0000,0x700e,0x4002,0x500a,0x0810,0x0000,0x0240,0x0180,
                0x0180,0x0240,0x0000,0x0810,0x500a,0x4002,0x700e,0x0000,
 
0x07e0,0x07e0,0x07e0,0x07e0,0x03c0,0xf00f,0xf81f,0xf81f,0xf81f,
                0xf81f,0xf00f,0x03c0,0x07e0,0x07e0,0x07e0,0x07e0,
0x0000,0x700e,0x4002,0x500a,0x0810,0x0000,0x0240,0x0180,
                 0x0180,0x0240,0x0000,0x0810,0x500a,0x4002,0x700e,0x0000};
/*the fn name is as such given by yashavant p.kanetkar,since i feel that the fn-name itself is self explanatory*/
/* interrupt-0x33
service no:
0-Reset mouse and get status
1-Show mouse pointer
2-Hide mouse pointer
3-get mouse coordinates and button status
4-Set mouse pointer position
7-Set horizontal limits for pointer
8-Set vertical limits for pointer*/
/*Note i have given you the most useful mouse control function whether it is skillfully handled in this source or not.Utilise it according to your need effectively*/
/* initialises mouse*/
int initmouse()
{
 i.x.ax=0;/*service no*/
 int86(0x33,&i,&o);
 return(o.x.ax);
}
/*display mouse pointer*/
void showmouseptr()
{
 i.x.ax=1;
 int86(0x33,&i,&o);
}
/*hide mouse pointer*/
void hidemouseptr()
{
 i.x.ax=2;
 int86(0x33,&i,&o);
}
/*gets mouse coordinates and button status*/
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;
}
/*set mouse pointer position(note:-Will not restrict after positioning)*/
void setmousepos(int x1,int y1)
{
 i.x.ax=4;
 i.x.cx=x1;
 i.x.dx=y1;
 int86(0x33,&i,&o);
}
/*Restrict mouse pointer within the horizontal and vertical limit*/
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);
}
/*To change your cursor*/
void changecursor(unsigned int shape[32])
{
 i.x.ax=9;
 i.x.bx=0;
 i.x.cx=0;
 i.x.dx=shape;
 segread(&s);
 s.es=s.ds;
 int86x(0x33,&i,&i,&s);
}
 
void main()
{
int gd=DETECT,gm,button,x,y,i,choice;
initgraph(&gd,&gm,"  ");
if(initmouse()==0)
{
closegraph();
puts("mouse not initialised");
exit(1);
}
i=0;
changecursor(c[i]);
setfillstyle(1,9);
bar(0,0,640,480);
setcolor(15);outtextxy(200,250,"To exit press any key u want");
outtextxy(150,270,"Press any mousebutton to continue anima..");
setcolor(0);rectangle(20,20,620,460);
restrictmouseptr(20,20,620,460);
showmouseptr();
setmousepos(320,240);
getmousepos(&button,&x,&y);
setcolor(0);
while(!kbhit())
{getmousepos(&button,&x,&y);
if(button==1||button==2||button==3){i=0;}
if(i<10)
{
/*if you does'nt feel realistic, please change delay as yor wish*/ 
     delay(200);
     hidemouseptr();
     changecursor(c[i]);
     i++;
     showmouseptr();
}
}
 getch();
}





 





Add comment to this page:
Your Name:
Your Email address:
Your message:

 
  Totally, there have been 14997 visitors (30315 hits) on this page! (This webpage published on 27.09.2012)  
 
=> Do you also want a homepage for free? Then click here! <=