Results 1 to 14 of 14

Thread: [Resolved] Console Position

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    [Resolved] Console Position

    I know how I can set the caret to a specific x, y in the console window, but is there a way to retrieve the current coordinates of it?

    I'm trying to make a function to go to the nth column in the console, but I want it to stay in the same row. I'm going to use this function in replace of setw() functions.

    Thanks in advance for any help.
    Last edited by The Hobo; Oct 14th, 2002 at 03:14 PM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    hmm.

    perhaps you can havea a 2d array, and then set it wherever you want, and have a function that will update the screen with the array?
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by nabeels786
    hmm.

    perhaps you can havea a 2d array, and then set it wherever you want, and have a function that will update the screen with the array?
    I'm not sure what you mean...?

    But I just found this: GetConsoleCursorInfo()

    I'm going to see if I can figure out what it does real quick.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Man...I figured there had to be a way to do this
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    it looks pretty complicated, I don't have time to whip up anything (sisters birthday dinner hehe)...but heres what I found:

    http://msdn.microsoft.com/library/de...bufferinfo.asp

    BOOL GetConsoleScreenBufferInfo(
    HANDLE hConsoleOutput,
    PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
    );

    Parameters
    hConsoleOutput
    [in] Handle to a console screen buffer. The handle must have the GENERIC_READ access right. For more information, see Console Buffer Security and Access Rights.
    lpConsoleScreenBufferInfo
    [out] Pointer to a CONSOLE_SCREEN_BUFFER_INFO structure that receives the console screen buffer information.
    and about that consolescreenbuffer thing:

    http://msdn.microsoft.com/library/de...r_info_str.asp

    typedef struct _CONSOLE_SCREEN_BUFFER_INFO { COORD dwSize; COORD dwCursorPosition; WORD wAttributes; SMALL_RECT srWindow; COORD dwMaximumWindowSize;
    } CONSOLE_SCREEN_BUFFER_INFO;
    Members
    dwSize
    A COORD structure that contains the size of the console screen buffer, in character columns and rows.
    dwCursorPosition
    A COORD structure that contains the column and row coordinates of the cursor in the console screen buffer.
    so it looks like with those 2 functions you can find the coordinates (seems like an awefull lot of work for it though)


  6. #6

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Thanks! I'll see what I can do with that
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    I don't think I'll have much time tonight...but if I do I'll give it a shot also

  8. #8

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I tried this:

    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    int main() {
    
    	CONSOLE_SCREEN_BUFFER_INFO info;
    
    	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    
        GetConsoleScreenBufferInfo(hConsole, info);
    
    	cout << info.dwSize.Y << endl;
    
        return 0;
    }
    Gave the error:

    C:\Download\The Guitar Hobo\Programming\Cpp Stuff\skipto\skipto.cpp(11) : error C2664: 'GetConsoleScreenBufferInfo' : cannot convert parameter 2 from 'struct _CONSOLE_SCREEN_BUFFER_INFO' to 'struct _CONSOLE_SCREEN_BUFFER_INFO *'
    So I tried this:

    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    int main() {
    
    	CONSOLE_SCREEN_BUFFER_INFO *info;
    
    	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    
        GetConsoleScreenBufferInfo(hConsole, info);
    
    	cout << info.dwSize.Y << endl;
    
        return 0;
    }
    and got:

    C:\Download\The Guitar Hobo\Programming\Cpp Stuff\skipto\skipto.cpp(13) : error C2228: left of '.dwSize' must have class/struct/union type
    What am I doing wrong here?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by SteveCRM
    I don't think I'll have much time tonight...but if I do I'll give it a shot also
    That's cool, man. Any help you can give and have given is much appreciated.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    When I do do something to get it working, it just gives me 25?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    huh...i get the same...hmmmm...25 is the height of the console isn't it? maybe...eh I'll think about it

    it returns 80 for the x, thats also an extreme of the console...hmmm

  12. #12

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    doh!

    We were using dwSize. dwCursorPosition has the right values.

    It works perfectly (I think)

    Thanks a lot, man!
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    This is what I did with it, btw:

    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    void setXPos(int x);
    
    int main() {
    
        setXPos(10);
        cout << "Test!" << endl << endl;
    
        return 0;
    }
    
    
    void setXPos(int x) {
        HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
        COORD coord;
    
        GetConsoleScreenBufferInfo(hConsole, &csbiInfo);
    
        coord.X = x;
        coord.Y = csbiInfo.dwCursorPosition.Y;
    	
        SetConsoleCursorPosition(hConsole, coord);
    }
    Thanks again, Steve!
    My evil laugh has a squeak in it.

    kristopherwilson.com

  14. #14
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    lol woops anytime

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width