Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

ReadConsoleOutput changes the size of my SMALL_RECT... help!
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.



Report this thread to moderator Post Follow-up to this message
Old Post
Eric A. Johnson
03-26-05 08:57 PM


Re: ReadConsoleOutput changes the size of my SMALL_RECT... help!
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.
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Kelly
04-01-05 01:58 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Visual Studio archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:49 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.