سلام، من كلي گشتم اين دستوران رو پيدا كردم، اميدوارم به دردت بخورند،
#include<iostream>
#include<windows.h>
#include<stdio.h>
using namespace std;
void gotoxy(int x,int y);
void GetMousePosWin(long &x, long &y);
int main()
{
long int a=20,b=20;
gotoxy(20,5);
cout<<"_____";
gotoxy(20,7);
cout<<"_____";
while(1)
{
gotoxy(0,0);
GetMousePosWin(a,b);
cout<<"\r\t\t\t";
cout<<"\r"<<a<<"\t"<<b<<endl;
}
return 0;
}
void GetMousePosWin(long &x, long &y)
{
// creates the handle i need to use
HANDLE OutputH;
INPUT_RECORD Inrec;
DWORD evRead;
HANDLE hStdIn;
DWORD dwMode;
bool Captured=false;
//GetConsoleMode(hStdIn, &dwMode);
hStdIn = GetStdHandle(STD_INPUT_HANDLE);
GetConsoleMode(hStdIn, &dwMode);
SetConsoleMode(hStdIn, (dwMode & (ENABLE_MOUSE_INPUT)));
// grab the handle to the console so i can use it
OutputH = GetStdHandle(STD_OUTPUT_HANDLE);
do
{
PeekConsoleInput(hStdIn, &Inrec, 1, &evRead);
if(evRead>0)
{
ReadConsoleInput(hStdIn, &Inrec, 1, &evRead);
switch (Inrec.EventType )
{
case MOUSE_EVENT:
Captured = true;
break;
case KEY_EVENT:
Captured = true;
break;
}
}
} while(!Captured);
x= Inrec.Event.MouseEvent.dwMousePosition.X ;
y= Inrec.Event.MouseEvent.dwMousePosition.Y ;
if(Inrec.Event.MouseEvent.dwButtonState==1)//left MouseDown=1 & right MouseDown=2
{
if((x>=20)&&(y>=5)&&(x<=24)&&(y<=7))
{
cout<<"\nFGJH";
}
}
}
void gotoxy(int x,int y) /* tabe gotoxy curser ro be mokhtasate khasi mibare gotoxy 2 argoman dare ke x baraye satr va y baraye sootoon ast*/
{
HANDLE hConsole = GetStdHandle ( STD_OUTPUT_HANDLE );
if (INVALID_HANDLE_VALUE != hConsole)
{
COORD pos = {x,y};
SetConsoleCursorPosition( hConsole, pos );
}
}