VB icon

mouse click

Email
Submitted on: 1/1/2015 5:13:00 PM
By: Mohammed Ali Akbani (from psc cd)  
Level: Beginner
User Rating: By 4 Users
Compatibility: C++ (general), Borland C++
Views: 1309
 
     it is a code that allows the use of mouse in text maode. i found many codes that used mouse in graphical mode but none for text mode. this is my way of solving it. feel free to vote for me
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: mouse click
// Description:it is a code that allows the use of mouse in text maode. i found many codes that used mouse in graphical mode but none for text mode. this is my way of solving it. feel free to vote for me
// By: Mohammed Ali Akbani (from psc cd)
//**************************************

//	Author:		Mohammed Ali Akbani
//	E-mail:		duke@samwonline.com
//	Level :		beginner
//Please do not repost it in you name and vote for me.
#include<iostream.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
class mouse
{
 private:
 union REGS i,o;
 struct SREGS s;
 public:
 mouse()
 {
initmouse();
showmouseptr();
 }
 void initmouse()
 {
i.x.ax=0;
int86(0x33,&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 x=0,y=0,button=0;
mouse m;
int controller=1;
struct btn
{
	int bx1;
	int by1;
	int bx2;
	int by2;
};
void main()
{
// int gdriver = DETECT, gmode;
// initgraph(&gdriver, &gmode, "\\borlandc\\bgi");
	clrscr();
	gotoxy(2,2);
	cout<< "CLICK";
	btn b1 = {0,0,48,16};
	gotoxy(2,4);
	cout<< "CLICK";
	btn b2 ={0,16,48,32};
	gotoxy(2,6);
	cout<< "CLICK";
	btn b3 = {0,32,48,48};
	m.showmouseptr();
	while((!kbhit())&&(controller==1))
	{
		m.getmousepos(button,x,y);
		gotoxy(20,20);
		cout<< x << " " << y;
		if((x>b1.bx1)&&(y>b1.by1)&&(x<b1.bx2)&&(y<b1.by2)&&(button==1))
		{
			delay(300);
			gotoxy(12,12);
			cout << "You clicked #1";
		}
		else if((x>b2.bx1)&&(y>b2.by1)&&(x<b2.bx2)&&(y<b2.by2)&&(button==1))
		{
			delay(300);
			gotoxy(12,12);
			cout << "You clicked #2";
		}
		else if((x>b3.bx1)&&(y>b3.by1)&&(x<b3.bx2)&&(y<b3.by2)&&(button==1))
		{
			delay(300);
			gotoxy(12,12);
			cout<< "You clicked #3";
		}
	}
}


Other 4 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.