Need Clr Screen Code

This is a discussion on Need Clr Screen Code within the C++ Programming forums, part of the General Programming Boards category; flush empties the output buffert and makes sure that whatever is in there it will be outputed (I think lol). ...

  1. #16
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    flush empties the output buffert and makes sure that whatever is in there it will be outputed (I think lol). This comes in handy when you really want to make sure everything in the output buffert will be printed to the screen for example. Also endl will call the same function aswell.

  2. #17
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >is there a better way than this?
    Yes, but you fall into the realm of platform and compiler dependent solutions with them.
    My best code is written with the delete key.

  3. #18
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    Highly non-portable.

    Code:
    #include <windows.h>
    
    void
     clear(int left, int top, int right, int bottom, int fill = ' ')
    {
      int length = right - left;
      COORD coord; 
      DWORD unused;
      HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
      
         for(coord.X = left, coord.Y = top; coord.Y < bottom; ++coord.Y)
       {
         FillConsoleOutputCharacter(screen, fill, length, coord, &unused);
       }
    }
    
    
    
    
    void
     clear(int fill = ' ')
    {
      CONSOLE_SCREEN_BUFFER_INFO info;
    
      GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
    
      clear(0, 0, info.dwSize.X, info.dwSize.Y, fill);
    }
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  4. #19
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    If you using the Win32 console, try this code snippet I got from a book entitled "Game Programming All-In-One" (with a few modifications):

    Code:
    void clearscreen(void)
    {
      HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
      COORD start;
      DWORD written;
      WORD forecolor = 7;
      WORD backcolor = 0;
     
      start.X = 0;
      start.Y = 0;
     
      FillConsoleOutputAttribute(screen, forecolor + (backcolor << 4), 80 * 25, start, &written);
      FillConsoleOutputCharacter(screen, ' ', 80 * 25, start, &written);
      SetConsoleCursorPosition(screen, start);
    }
    As a quick note, you'll need to #include <windows.h>.

    Edit: Hmm... appears I should've looked to see if there was a second page. Oh well... at least mine doesn't leave the previous colors.
    Last edited by Frobozz; 11-03-2003 at 04:09 PM.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Render text
    By Livijn in forum C++ Programming
    Replies: 6
    Last Post: 07-06-2007, 03:32 PM
  2. 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
  3. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM
  4. easy visual c++ program problem,
    By DAIALOS in forum C++ Programming
    Replies: 2
    Last Post: 01-10-2003, 11:38 AM
  5. Shut off DOS screen automatically to Windows
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 11-08-2001, 06:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21