Getting Cursor Position

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?...

  1. #1
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718

    Getting Cursor Position

    How do you find out the x & y coordinates of the cursor in the console window?

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    wherex() & wherey() in conio.h do that. But conio is not std.

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    I'm using VC++6, and it doesn't seem to like that. Does anyone know how else to get it?

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    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;


Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21