How would I check what characters are on the screen buffer?

This is a discussion on How would I check what characters are on the screen buffer? within the C++ Programming forums, part of the General Programming Boards category; Here is what Ive been trying: Code: bool CBlock::move(int _x, int _y) { CHAR_INFO charInfo[80*25]; COORD bufferSize = { 80, ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    118

    How would I check what characters are on the screen buffer?

    Here is what Ive been trying:
    Code:
    bool CBlock::move(int _x, int _y) {
    	CHAR_INFO charInfo[80*25];
    	COORD bufferSize = { 80, 25 };
    	COORD bufferCoord = { 0, 0 };
    	SMALL_RECT smallRect;
    	if (!ReadConsoleOutput(GetStdHandle(STD_OUTPUT_HANDLE), charInfo, bufferSize, bufferCoord, &smallRect)) {
    		MessageBox(0, "ERROR", "ERROR", MB_OK);
    	}
    	if (charInfo[_x*80+_y].Char.AsciiChar != '#') {
    		x = _x;
    		y = _y;
    		return true;
    	}
    	else return false;
    }
    So according to this, if _x and _y on the screen buffer are '#', the fucntion should return false, but it doesnt! what am I doing wrong? this is killing me!
    Why drink and drive when you can smoke and fly?

  2. #2
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    I dont know if this is the problem, but isnt it:

    array[wanted y-value * max x-value + wanted x-value]

    AKA, switch to:

    charInfo[_y * 80 + _x]
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    118
    Now that I think about it, that does make more sense, but it still doesnt work
    Why drink and drive when you can smoke and fly?

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Quote Originally Posted by MSDN
    lpReadRegion
    [in, out] Pointer to a SMALL_RECT structure. On input, the structure members specify the upper-left and lower-right coordinates of the console screen buffer rectangle from which the function is to read. On output, the structure members specify the actual rectangle that was used.
    ~~~~

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    118
    Thanks man, you saved my monitor from flying out the window.
    Why drink and drive when you can smoke and fly?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Not working in linux...
    By mramazing in forum C++ Programming
    Replies: 6
    Last Post: 01-08-2009, 01:18 AM
  2. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  3. Replies: 16
    Last Post: 10-29-2006, 04:04 AM
  4. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 03:56 PM
  5. Tetris Questions
    By KneeGrow in forum Game Programming
    Replies: 19
    Last Post: 10-28-2003, 10:12 PM

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