I want to print something in the position where the mouse cursor is, so I use POINT cursorPos; GetCursorPos(&cursorPos);
to get the position of mouse cursor.
Then I set the console cursor to the position, and print the mouse coordinates. However the result is not correct.
Here's the code:
#include<iostream>
#include<Windows.h>
#include <conio.h>
#include <stdio.h>
using namespace std;
void gotoxy(int column, int line){
COORD coord;
coord.X = column;
coord.Y = line;
SetConsoleCursorPosition(
GetStdHandle(STD_OUTPUT_HANDLE),
coord
);
}
int main(){
while (1){
POINT cursorPos;
GetCursorPos(&cursorPos);
system("pause");
gotoxy(cursorPos.x, cursorPos.y);
cout << cursorPos.x << " " << cursorPos.y;
}
}
Thank U~