Clearing the screen

This is a discussion on Clearing the screen within the C++ Programming forums, part of the General Programming Boards category; Since there seem to be no newbies to ask the question for the next couple of days I thought I'd ...

  1. #1
    tgm
    tgm is offline
    Registered User tgm's Avatar
    Join Date
    Jun 2002
    Posts
    150

    Clearing the screen

    Since there seem to be no newbies to ask the question for the next couple of days I thought I'd do it.

    How can I clear the screen in text mode? I'm using WindowsXP but I want to make real kewl DOS games. (wait that's too much information, ignore that last sentence)

  2. #2
    Stoned_coder
    Guest
    straight from the FAQ.
    Ill let you off this time as u may have had trouble accessing it.
    1.0 CLEARING THE SCREEN: (Credit: robwhit)
    OPTION 1

    put this at the top of your source file:
    #include <conio.h>

    put this where you want the screen to clear:
    clrscr();

    Advantages:
    Works fast. Simple.

    Disadvantages:
    Only DOS compilers have this function.

    OPTION 2

    putchar some newlines until everything is scrolled off of the screen.

    Advantages:
    It works.

    Disadvantages:

    The screen isn't always the same size, even in text modes, so there could be more lines than you think are there. (And its slow and hackish.)

    OPTION 3

    Use a text-mode library like curses or a port of it or something like that.

    Advantages:
    Portable, provided that you have the library

    Disadvantages:
    You have to get the library

    OPTION 4

    Write directly to video memory, clearing all the bits.

    Advantages:
    It works.

    Disadvantages: Some OSs don't allow you to directly access hardware, finding out how to write to video memory can be a pain, don't expect it to be too portable...

    OPTION 5

    For all UNIX systems, using curses:

    #include <curses.h>



    void clrscr()

    {

    static int init;

    if (init == 0)

    {

    initscr();

    init = 1;

    }

    clear();

    refresh();

    }


    OPTION 6

    Throw the monitor out the window

    Advantages:
    Pretty fail-proof
    Releases your anger

    Disadvantages:
    No more monitor.
    If you forgot to unplug it, other computer peripherals might follow it in a racing frenzy
    You have to open the window and take the screen out (the mesh thingie that keeps bugs out.... supposedly...)
    (Note from webmaster: Not portable. Difficult to write code to throw monitor out window.)

    WINDOWS OPTION: (Credit: Sunlight)

    Just call the function clrscr(). Simple as that.

    #include <windows.h>



    void clrscr()

    {

    COORD coordScreen = { 0, 0 };

    DWORD cCharsWritten;

    CONSOLE_SCREEN_BUFFER_INFO csbi;

    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);

    }

  3. #3
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    The skunkmeister lives!

  4. #4
    Unregistered
    Guest

    Re: Clearing the screen

    Originally posted by tgm
    Since there seem to be no newbies to ask the question for the next couple of days I thought I'd do it.

    How can I clear the screen in text mode? I'm using WindowsXP but I want to make real kewl DOS games. (wait that's too much information, ignore that last sentence)
    XP is trying to do away with DOS for system stability as they think of it as Dead Operating System (those bastards).
    go tell them those people who ask to learn Windows Programming instead.

    here's a taste of bios int 10h programming:

    Code:
    ...
    
    ;clearing the screen:
    
    mov  ax , 0600h
    mov  bh , 07
    mov  cx , 0000
    mov  dx , 184fh
    int  10h
    
    ...
    _____
    toaster

  5. #5
    Unregistered
    Guest
    Originally posted by -KEN-
    The skunkmeister lives!
    all hail to thy skunkmeister!

    _____
    toaster

  6. #6
    golfinguy4
    Guest
    TGM, is it just me, or are some people thick-headed?

    P.S. Everyone, it was a joke. He doesn't really need to know how to clear the screen.

  7. #7
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    WTF, this bug is really ........ing me off.

  8. #8
    toaster
    Guest
    hey, watch your language!
    there could be 13 year olds wandering in this board!
    spare thy virgin ears!
    no offense, by the way.
    don't take it seriously.

    back to the topic:
    I suppose they know how to use a FAQ board, right?

    _____
    toaster

  9. #9
    tgm
    tgm is offline
    Registered User tgm's Avatar
    Join Date
    Jun 2002
    Posts
    150
    Hehehehe.

    That was amusing. I thought the post was quite sarcastic in tone. I guess I'll have to try harder from now on. I'll be deleting this thread shortly.

  10. #10
    Ken Fitlike
    Guest
    Well, as you're deleting the thread anyway - I thought it was hilarious!

  11. #11
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    >OPTION 6

    Throw the monitor out the window

    Advantages:
    Pretty fail-proof
    Releases your anger

    Disadvantages:
    No more monitor.
    If you forgot to unplug it, other computer peripherals might follow it in a racing frenzy
    You have to open the window and take the screen out (the mesh thingie that keeps bugs out.... supposedly...)
    (Note from webmaster: Not portable. Difficult to write code to throw monitor out window.)
    <

    my personal favorite...

    oh, and tgm, well, as a matter of fact i don't recommend you delete this thread just yet, hold on a bit... it's useful perhaps in the FAQ forum...
    hasafraggin shizigishin oppashigger...

  12. #12
    Still A Registered User DISGUISED's Avatar
    Join Date
    Aug 2001
    Posts
    499
    My all time favorite option...

    credit quzah
    Maybe if you shake it, side to side, like an etch-a-sketch...

    Hahahaha

  13. #13
    tgm
    tgm is offline
    Registered User tgm's Avatar
    Join Date
    Jun 2002
    Posts
    150
    OK, deleting the post is on hold.

  14. #14
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    What you need is a glass-cleaning agent and a soft cloth for the wiping the screen.

  15. #15
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796

    Lightbulb

    >How can I clear the screen in text mode?
    Turn the page. But despite how correct this is on so many levels, I imagine the majority of people asking how to clear the screen would be baffled and eventually rationalize their ignorance by believing that it was a joke. The rest of you get to choose whether it was indeed a joke or actually an effective and quite brilliant solution. Of course, it could be both.

    >Maybe if you shake it, side to side, like an etch-a-sketch...
    Or better yet, actually use an etch-a-sketch. That way we would be saved from answering this inane question ten times a week.

    -Prelude
    My best code is written with the delete key.

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  2. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  3. clearing the screen
    By ssharish in forum C Programming
    Replies: 2
    Last Post: 02-01-2005, 09:00 PM
  4. 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, 03:41 AM
  5. Clearing the screen
    By Shadow in forum C Programming
    Replies: 4
    Last Post: 05-23-2002, 02:40 PM

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