News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Example code To Make a console window clear the console window

Started by nandagopal, Nov 29, 2008, 10:17 PM

Previous topic - Next topic

nandagopal

The ConsoleClearer class's Clear method clears the console. It gets a handle to stdout, gets information about the console screen buffer, fills the buffer with spaces, and then places the cursor in the upper left corner.


' Subroutine used to clear the Console screen.
Public Sub Clear()
    Dim hConsoleHandle As IntPtr
    Dim hWrittenChars As IntPtr
    Dim strConsoleInfo As CONSOLE_SCREEN_BUFFER_INFO
    Dim strOriginalLocation As COORD

    ' Get Handle for standard output
    hConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE)

    ' Get information about the standard output buffer of
    ' the Console
    GetConsoleScreenBufferInfo(hConsoleHandle, _
        strConsoleInfo)

    ' Fill output buffer with Empty characters (ASCII 32)
    FillConsoleOutputCharacter(hConsoleHandle, EMPTY, _
        strConsoleInfo.dwSize.X * strConsoleInfo.dwSize.Y, _
        strOriginalLocation, hWrittenChars)

    ' Set the Console cursor back to the origin
    SetConsoleCursorPosition(hConsoleHandle, _
        strOriginalLocation)
End Sub