help w/ReadConsoleOutputCharacter()

This is a discussion on help w/ReadConsoleOutputCharacter() within the C++ Programming forums, part of the General Programming Boards category; I am trying to find a way to read a character that has already been displayed on the screen. I ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    27

    help w/ReadConsoleOutputCharacter()

    I am trying to find a way to read a character that has already been displayed on the screen. I found a function called ReadConsoleOutputCharacter. I am pretty sure this is what I want but I wasn't sure how to use it and I couldn't find any help on google.
    "Computers aren't intelligent, they only think they are."

    **infected by Blizzarddog**
    I am a signature virus. Please add me to your signature so that I may multiply

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    Heres the msdn link on that function
    http://msdn.microsoft.com/library/de...tcharacter.asp
    Woop?

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    27
    yes, this is where i found the function but i was confused about what all the parameters should equal and stuff like that
    "Computers aren't intelligent, they only think they are."

    **infected by Blizzarddog**
    I am a signature virus. Please add me to your signature so that I may multiply

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >but i was confused about what all the parameters should equal and stuff like that

    Try this.
    Code:
       char buf[BUFSIZ];
       COORD coord = {0,0};
       DWORD num_read;
    
       HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
       if (ReadConsoleOutputCharacter(hConsole, (LPTSTR) buf, (DWORD) BUFSIZ, coord, (LPDWORD) &num_read) == 0)
       {
          cout << "Error reading console." << endl;
          return 1;
       }
       cout << buf;
    If you haven't already, check the FAQ for a clear screen function and gotoxy function.

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Well, I've never used any of these special Windows Console functions, but I have done some Windows programming, so maybe I can help. (?)

    All of these parameter types are structures and typedef's defined in windows.h:
    HANDLE
    LPTSTR
    DWORD
    COORD
    LPDWORD

    DWORD is simply a variable (long integer?), and LP means "long pointer", so LPSTR is a pointer to a c-style string (character array), and LPDWORD is a pointer to a DWORD.

    There should be some information on these "types" in your compiler's help file.

    You can use your own variable names if you want, but you will have to define and initialize them before calling the function.

    Like swoopy shows, GetStdHandle() should be used to initialize hConsoleOutput (or hConsole if you wish to use that name).

    I'm not sure about initializing COORD. I assume that X and Y are in pixels. With Windows programs, there is more than one way to reference window coordinates, but I think pixels are the default.
    Last edited by DougDbug; 06-16-2004 at 07:55 PM.

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