How do you find out the x & y coordinates of the cursor in the console window?
This is a discussion on Getting Cursor Position within the C++ Programming forums, part of the General Programming Boards category; How do you find out the x & y coordinates of the cursor in the console window?...
How do you find out the x & y coordinates of the cursor in the console window?
wherex() & wherey() in conio.h do that. But conio is not std.
-
I'm using VC++6, and it doesn't seem to like that. Does anyone know how else to get it?
Here's one way to do it:
PHP Code:#include <windows.h>
int GetX()
{
CONSOLE_SCREEN_BUFFER_INFO TempInfo;
COORD coord;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole,&TempInfo);
coord = TempInfo.dwCursorPosition;
return coord.X;
}
int GetY()
{
CONSOLE_SCREEN_BUFFER_INFO TempInfo;
COORD coord;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole,&TempInfo);
coord = TempInfo.dwCursorPosition;
return coord.Y;
}