ReadConcoleOutput is unclear

Hello, I am trying to make something like console interface. All i want to do here is to copy a rectangle of console screen one line higher.
1
2
3
4
5
6
cl.Y = 2;
cl.X = 1;
ReadConsoleOutput(hnd, pci, wndsz, cl, &psr);
cl.Y = 1;
WriteConsoleOutput(hnd, pci, wndsz, cl, &psr);
}

Why isn't this working? What to do to copy the buffer one line higher? Thanks.
You have mis-understood the arguments to the functions.

The lpBuffer is an array you keep in your program.

It is dwBufferSize cells wide and high.

You can write/read a specific area of your buffer by specifying the upper-left corner with dwBufferCoord. Unless you plan to do some tricky sprites with a single buffer, your upper-left corner should be at { 0, 0 }. (This is what you want.)

The lpReadRegion and lpWriteRegion rectangles are where to read/write in the Console Buffer.

Example, given:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
bool move_rect(
  int x,     int y,
  int new_x, int new_y,
  int width, int height
  ) {
  HANDLE     hStdOut      = GetStdHandle( STD_OUTPUT_HANDLE );
  PCHAR_INFO buffer       = new CHAR_INFO[ width * height ];
  COORD      buffer_size  = { width, height };
  COORD      buffer_index = { 0, 0 };  // read/write rectangle has upper-right corner at upper-right corner of buffer
  SMALL_RECT read_rect    = { x,     y,     x     + width - 1, y     + height - 1 };
  SMALL_RECT write_rect   = { new_x, new_y, new_x + width - 1, new_y + height - 1 };

  bool result = ReadConsoleOutput(  hStdOut, buffer, buffer_size, buffer_index, &read_rect )
             && WriteConsoleOutput( hStdOut, buffer, buffer_size, buffer_index, &write_rect );

  delete [] buffer;

  return result;
  }

I know that MS documentation takes a little getting used to, but it is always usually very complete.

Hope this helps.
Now i even understand why i got that result... Thanks. And double thanks because i used this function and it works just fine!
Topic archived. No new replies allowed.