Thread: Clear Screen Code

  1. #1
    Registered User
    Join Date
    Feb 2003

    Clear Screen Code

    Can someone please explain this function? I found it in one of the threads on this forum, but I can't decipher it.

    void clrscr()
       COORD coordScreen = { 0, 0 };
       DWORD cCharsWritten;
       DWORD dwConSize;
       HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
       GetConsoleScreenBufferInfo(hConsole, &csbi);
       dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
       FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
       GetConsoleScreenBufferInfo(hConsole, &csbi);
       FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
       SetConsoleCursorPosition(hConsole, coordScreen);
    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Feb 2003
    I do understand what it does, but not how it does it.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    You can look up each function here. Like GetConsoleScreenBufferInfo().

    Also, Windows specific questions should go on this message board.


  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    What don't you understand?

    The screen of a console is simply a buffer of characters. What that code does is gets the buffer, replaces the buffers existing contents with spaces then homes the cursor.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  2. Clear Screen
    By KneeGrow in forum C++ Programming
    Replies: 1
    Last Post: 10-24-2003, 10:17 PM
  3. more specific clear screen
    By UniqueuserName in forum C++ Programming
    Replies: 2
    Last Post: 12-10-2002, 11:38 AM
  4. How do I clear screen in a C program?
    By DarkboyBlue in forum C Programming
    Replies: 6
    Last Post: 08-21-2002, 11:26 AM
  5. clear screen
    By y2jasontario in forum C Programming
    Replies: 2
    Last Post: 04-04-2002, 12:50 PM