vibudh is talking

The C++ code that we are going to discuss is a simple part of a program that can be used to insert a mouse pointer in your C++ program, however the code is self sufficient and will work perfectly in any standard C++ compiler. This part of the program when inserted in your C++ program will make your project user friendly and at the same time give you an edge over other programs by enhancing the execution. It is advisable to include this part of the program before you start the project. Any relevant query will be most welcome. The source code for inserting the mouse pointer is as follows with relevant comment lines.

 
/*relevant header files for the program */
#include 
#include
#include 
#include
#include

int intmouse();
/*function to show mouse pointer*/
void showmouseptr(); 

/*gets the current position of the mouse */
void getmousepos(int *, int *, int*);

/*restricts the mouse in the graphical area */
void restrictmouseptr(int x,int y,int x1,int y1);

union REGS i,o,a,b;
int intmouse()
{
	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 x,int y,int x1,int y1)
{
	i.x.ax=7;
	i.x.cx=x;
	i.x.dx=x1;
	int86(0x33,&i,&o);
	i.x.ax=8;
	i.x.cx=y;
	i.x.dx=y1;
	int86(0x33,&i,&o);
}

void getmousepos(int *p,int *x,int *y)
{
	i.x.ax=3;

	int86(0x33,&i,&o);
	*p=o.x.bx;
	*x=o.x.cx;
	*y=o.x.dx;
}
void main()
{
 int gd=DETECT,gm;
 initgraph(&gd,&gm,"\\tc\\bgi");
 int x=getmaxx();
 int y=getmaxy();
 if(intmouse()==0)
  exit(1);
 showmouseptr();
 cleardevice();
 setcolor(WHITE);
 setbkcolor(BLACK);
 int button,n,m;
 outtextxy(x-100,y-50,"Exit...");
 getmousepos(&button,&n,&m); /*n=x-coordinate& m=y-coordinate*/
 int z=1;
 restrictmouseptr(1,1,x-1,y-1);

 while(z)
 {
  getmousepos(&button,&n,&m);
  /*this will keep in track with the current position of the mouse*/

  /*displaying the current position of the mouse */
  gotoxy(1,1);
  cout<<"n ="<<n<=532 && n<=592) && (m>=429 && m<=444))
  {
   exit(0);
   button=0;
   z=0;
  }
 }

 closegraph();
 restorecrtmode();
 getch();
 closegraph();
 restorecrtmode();
}

Now we will be discussing how this programme actually works and what does each function do. initgraph() is used to initialize the graph grid. showmouseptr() is used to show the mouse pointer in the output screen. cleardevice() is simply used to clear the scree. getmouseposition(&button,&n,&m) is used to get the present status of the mouse button and its present coordinates. restrictmouseptr() is used to prevent the mouse pointer to go out of bouonds, so that is does not go beyond the display screen. Here as you can see in the main() we are using a while loop, that stays true, and has infinite loop. This is important because we need the dynamic execution of the programme as long as the user does not press Exit… to get out of the programme. This while loop is also the place where other dynamic components of the program will be executed, as we discuss in some other projects that we take on. Hope this programme helps you in making your programme more interactive and user friendly. 

Advertisements

Comments on: "Inserting Mouse Pointer in your C++ program (for TC)" (11)

  1. I just want to tell you that I am just all new to blogging and site-building and really liked you’re website. Almost certainly I’m want to bookmark your blog . You actually come with fantastic writings. Regards for revealing your web-site.

  2. Thanks a lot as i had searched for long to get a program like this

  3. ya surely i will contact you often

  4. can you send some of your programs to me as an email.

    • Dear Ain,
      I would love to share my programs with all my blog followers so I will upload it on my blog so that you can see it. But the important thing is that if you are using it for your school projects you understand the programs well before you use it.
      What kind of programs are you interested in?

  5. Subash Sonar said:

    Sir,
    the code which you have supplimented get error in turbo c . And the main error is about the prototype function of initgraph.
    I shall be remain obliged to you if you kindly email me with full version source code.
    Thanks you.

  6. Subash Sonar said:

    R/Sir,
    The code which you have supplimented get error in turbo c . And the main error is about the prototype function of initgraph.
    I shall be remain obliged to you if you kindly email me with full version source code.
    Thanks you.

  7. Subash Sonar said:

    Actually i am a novice of programming language. Can you please help me?

  8. Subash Sonar said:

    Actually i am a novice of programming language.
    Can you please help me?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: