compatable clrscr
In a win32 consol app under mvc++, how do you clear the screen?
is there a cout member that does this?
dos.h is barely recognized, and i cannot use clrscr()
Something like this:
"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
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
ok, i get
error C2653: ''Win32Console'' : is not a class or namespace name
error C2065: ''hStdOut'' : undeclared identifier
error C2065: ''setPosition'' : undeclared identifier
error C2653: ''Win32Console'' : is not a class or namespace name
error C2065: ''hStdOut'' : undeclared identifier
error C2065: ''setPosition'' : undeclared identifier
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...
It took me a while to figure it out myself, but I believe this is the most appropriate way of doing it:
Edited by - Monolith on October 31, 2001 12:11:35 PM
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
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:
"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
//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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement