Thread: Need Clr Screen Code

  1. #16
    Registered User
    Join Date
    Aug 2003
    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
    >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
    Waterloo, Texas
    Highly non-portable.

    #include <windows.h>
     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);
     clear(int fill = ' ')
      GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
      clear(0, 0, info.dwSize.X, info.dwSize.Y, fill);
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

  4. #19
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    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):

    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 05:09 PM.

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, 12:38 PM
  5. Shut off DOS screen automatically to Windows
    By Unregistered in forum A Brief History of
    Replies: 2
    Last Post: 11-08-2001, 07:14 PM