This code in C clear the console:
Code: Select all
#include <windows.h>
void ClearScreen()
{
HANDLE hStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };
hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
if (hStdOut == INVALID_HANDLE_VALUE) return;
/* Get the number of cells in the current buffer */
if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
cellCount = csbi.dwSize.X *csbi.dwSize.Y;
/* Fill the entire buffer with spaces */
if (!FillConsoleOutputCharacter(
hStdOut,
(TCHAR) ' ',
cellCount,
homeCoords,
&count
)) return;
/* Fill the entire buffer with the current colors and attributes */
if (!FillConsoleOutputAttribute(
hStdOut,
csbi.wAttributes,
cellCount,
homeCoords,
&count
)) return;
/* Move the cursor home */
SetConsoleCursorPosition( hStdOut, homeCoords );
}
Code: Select all
Procedure Cls()
Protected hStdOut = GetStdHandle_(#STD_OUTPUT_HANDLE)
Protected count
Protected cellCount
Protected homeCoords.COORD
homeCoords\x = 0
homeCoords\y = 0
Protected csbi.CONSOLE_SCREEN_BUFFER_INFO
If (hStdOut = #INVALID_HANDLE_VALUE)
Debug "Handler console non valido."
ProcedureReturn
EndIf
;Get the number of character cells in the current buffer.
If (GetConsoleScreenBufferInfo_(hStdOut, csbi.CONSOLE_SCREEN_BUFFER_INFO) = 0)
ProcedureReturn
EndIf
cellCount = (csbi\dwSize\X) * (csbi\dwSize\Y)
Debug "cellCount = " + Str(cellCount)
;Fill the entire screen With blanks.
If (FillConsoleOutputCharacter_(hStdOut,' ', cellCount, homeCoords.COORD,@count) = 0)
ProcedureReturn
EndIf
Debug "count = " + Str(count)
;Get the current text attribute.
If (GetConsoleScreenBufferInfo_(hStdOut, csbi.CONSOLE_SCREEN_BUFFER_INFO) = 0)
ProcedureReturn
EndIf
;Set the buffer's attributes accordingly.
If (FillConsoleOutputAttribute_(hStdOut,csbi\wAttributes,cellCount,homeCoords.COORD,@count) = 0)
ProcedureReturn
EndIf
Debug "cellCount = " + Str(cellCount)
;Put the cursor at its home coordinates.
SetConsoleCursorPosition_(hStdOut, homeCoords.COORD);
EndProcedure
OpenConsole()
PrintN("asdasdasdsadasdasdsadasdasdasdasdasdasdasdasdasdas")
PrintN("asdasdasdsadasdasdsadasdasdasdasdasdasdasdasdasdas")
Cls()
Delay(20000)
Thanks.