Archived

This topic is now archived and is closed to further replies.

compatable clrscr

This topic is 5890 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Something like this:
  
void Win32Console::clear()
{
//get the size of the window

CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo( hStdOut, &info );

int noChars = info.dwSize.X * info.dwSize.Y;

//upper left

COORD coord;
coord.X = 0;
coord.Y = 0;

//fill the screen with spaces

DWORD written;
FillConsoleOutputCharacter( hStdOut, '' '', noChars, coord, &written );

//reset the cursor

setPosition( 0, 0 );
}


"I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours." - - Stephen Roberts

Share this post


Link to post
Share on other sites
ok, i get

error C2653: ''Win32Console'' : is not a class or namespace name
error C2065: ''hStdOut'' : undeclared identifier
error C2065: ''setPosition'' : undeclared identifier

Share this post


Link to post
Share on other sites
quote:
Original post by EvilCrap
error C2653: ''Win32Console'' : is not a class or namespace name
error C2065: ''hStdOut'' : undeclared identifier
error C2065: ''setPosition'' : undeclared identifier


Those are his own classes and variables. You need to obtain a handle to the console and possibly to its screenbuffer. Read up on the Win32 Console functions. Everything inside that clear() function except the setPosition() function is legal Win32 (as you can see from your error messages). setPosition() is probably just equivalent to SetConsoleCursorPosition().

And why you would think dos.h would be recognized under Windows is beyond me...

Share this post


Link to post
Share on other sites
It took me a while to figure it out myself, but I believe this is the most appropriate way of doing it:

    
void console::clrscr() {
HANDLE outH;
DWORD writtenchars, writtenattrs;
COORD top_left={0,0};
CONSOLE_SCREEN_BUFFER_INFO cbsi;

outH=GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(outH,&cbsi);
FillConsoleOutputCharacter(outH,0,cbsi.dwSize.X*cbsi.dwSize.Y,top_left,&writtenchars);
FillConsoleOutputAttribute(outH,cbsi.wAttributes,cbsi.dwSize.X*cbsi.dwSize.Y,top_left,&writtenattrs);
SetConsoleCursorPosition(outH,top_left);

CloseHandle(outH);
}



Edited by - Monolith on October 31, 2001 12:11:35 PM

Share this post


Link to post
Share on other sites
My fault...I should have cleaned it up first. I took this straight out of a console wrapper class I wrote, and sort of thought you could extrapolate the missing bits(I forgot that hStdOut wasnt defined in there). Anyway, this will work:

  
//get the handle to standard output

HANDLE hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );

//get the size of the window

CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo( hStdOut, &info );

int noChars = info.dwSize.X * info.dwSize.Y;

//upper left

COORD coord;
coord.X = 0;
coord.Y = 0;

//fill the screen with spaces

DWORD written;
FillConsoleOutputCharacter( hStdOut, '' '', noChars, coord, &written );

SetConsoleCursorPosition( hStdOut, coord );





"I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours." - - Stephen Roberts

Share this post


Link to post
Share on other sites