Home > Archive > Visual Studio > March 2005 > ReadConsoleOutput changes the size of my SMALL_RECT... help!
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
ReadConsoleOutput changes the size of my SMALL_RECT... help!
|
|
| Eric A. Johnson 2005-03-26, 3:57 pm |
| Hello All,
I'm having a problem with the below code. I am trying to copy an area
of screen space into an X by Y array of type CHAR_INFO before I overwrite it
with my "window". If I comment out the line that uses ReadConsoleOutput to
copy the screen area, the SMALL_RECT (WindowRectangle) is unchanged, and the
window displays just fine. However, if I uncomment it, it changes
WindowRectangle's dimensions to a much smaller size, resulting in a smaller
(or even nonexistant) window. How do I fix this? I'm at my wit's end.
Below is the relevant code. If somebody needs more or all of the source, I
will gladly post it -- just let me know. Thanks!
Sincerely,
Eric
/* Create a new window */
void ConsoleLib::WindowCreate(COORD Start, COORD Size, bool Border)
{
int column, row;
SMALL_RECT WindowRectangle;
COORD Position;
/*... more unrelated code here ...*/
// Make an array (buffer) to hold the screen info I will overwrite
CharInfo = new CHAR_INFO[Size.X, Size.Y];
// Save the screen information that will be overwritten into CharInfo
/*** NOTE: The line below is strangely altering WindowRectangle ***/
// ReadConsoleOutput(m_Screen, CharInfo, Size, Start, &WindowRectangle);
}
Notes: m_Screen is a handle to the console; CharInfo has been previously
declared as a pointer to CHAR_INFO; Border simply declares whether the
window has a visible border or not. I make all the important changes to
Size before declaring the new CharInfo array. Start is not changed at all.
It's still starting at the same position; it simply ends both the length and
width before it should. I am using the WindowRectangle borders to control
the display of the Window, to encertain that the information it saves is the
same as what is written over. I want to be able to replace the original
information when the window is destroyed.
| |
|
| The problem is probably that ReadConsoleOutput() is expecting to
write into a 2-dimensional array, but you allocated a 1-dimensional
array that was not large enough:
CharInfo = new CHAR_INFO[Size.X, Size.Y];
That statement allocated a 1-dimensional array of size "Size.Y".
You inadvertently used the comma-operator "," in "SizeX , SizeY".
The comma-operator merely evaluates the expressions on both
sides of the comma, then uses the right-hand-side as the value of
the expression: "Size.Y".
You probably wanted this:
CharInfo = new CHAR_INFO[SizeX* SizeY];
This will allocate enough space to hold X-rows of Y-columns
of CHAR_INFO.
This would explain how WindowRectangle is being affected. The
ReadConsoleOutput() function is writing past the end of the
CharInfo array and overwriting WindowRectangle.
"Eric A. Johnson" <nothere@dontlookforme.com> wrote in message
news:Ufi1e.15753$C47.10045@newssvr14.news.prodigy.com...
> Hello All,
>
> I'm having a problem with the below code. I am trying to copy an area
> of screen space into an X by Y array of type CHAR_INFO before I overwrite
it
> with my "window". If I comment out the line that uses ReadConsoleOutput
to
> copy the screen area, the SMALL_RECT (WindowRectangle) is unchanged, and
the
> window displays just fine. However, if I uncomment it, it changes
> WindowRectangle's dimensions to a much smaller size, resulting in a
smaller
> (or even nonexistant) window. How do I fix this? I'm at my wit's end.
> Below is the relevant code. If somebody needs more or all of the source,
I
> will gladly post it -- just let me know. Thanks!
>
> Sincerely,
>
> Eric
>
> /* Create a new window */
> void ConsoleLib::WindowCreate(COORD Start, COORD Size, bool Border)
> {
> int column, row;
> SMALL_RECT WindowRectangle;
> COORD Position;
> /*... more unrelated code here ...*/
>
> // Make an array (buffer) to hold the screen info I will overwrite
> CharInfo = new CHAR_INFO[Size.X, Size.Y];
>
> // Save the screen information that will be overwritten into CharInfo
> /*** NOTE: The line below is strangely altering WindowRectangle ***/
> // ReadConsoleOutput(m_Screen, CharInfo, Size, Start, &WindowRectangle);
>
> }
>
> Notes: m_Screen is a handle to the console; CharInfo has been previously
> declared as a pointer to CHAR_INFO; Border simply declares whether the
> window has a visible border or not. I make all the important changes to
> Size before declaring the new CharInfo array. Start is not changed at
all.
> It's still starting at the same position; it simply ends both the length
and
> width before it should. I am using the WindowRectangle borders to control
> the display of the Window, to encertain that the information it saves is
the
> same as what is written over. I want to be able to replace the original
> information when the window is destroyed.
>
>
|
|
|
|
|