Is there a way to clear the screen with out system("CLS")?
Thanks for reading this topic.
Clear screen without system("CLS")
Page 1 of 14 Replies - 856 Views - Last Post: 15 September 2011 - 03:01 AM
Replies To: Clear screen without system("CLS")
#2
Re: Clear screen without system("CLS")
Posted 15 September 2011 - 02:25 AM
There is no portable way to do so without relying on platform-specific console sizes.
Here is an (untested) example from MSDN with some questionable coding practice eliminated:
You can get the console handle by using GetConsoleWindow.
Here is an (untested) example from MSDN with some questionable coding practice eliminated:
#include <windows.h>
void cls( HANDLE hConsole )
{
COORD coordScreen = { 0, 0 };
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
GetConsoleScreenBufferInfo( hConsole, &csbi );
FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten );
GetConsoleScreenBufferInfo( hConsole, &csbi );
FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten );
SetConsoleCursorPosition( hConsole, coordScreen );
}
It seems to work by moving the cursor the the start, getting the size, filling the console and moving it back.You can get the console handle by using GetConsoleWindow.
This post has been edited by PlasticineGuy: 15 September 2011 - 02:26 AM
#3
Re: Clear screen without system("CLS")
Posted 15 September 2011 - 02:40 AM
What about for a console application?
Thanks for your effort by the way.
Thanks for your effort by the way.
#4
Re: Clear screen without system("CLS")
Posted 15 September 2011 - 02:44 AM
It IS for a console application. The WinAPI deals with any window, GUI or otherwise.
#5
Re: Clear screen without system("CLS")
Posted 15 September 2011 - 03:01 AM
I suck . . .
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|