Clearing the screen in a dos console window...

This is a discussion on Clearing the screen in a dos console window... within the C++ Programming forums, part of the General Programming Boards category; Hey all, WAIT! STOP! Don't flame me =P I've actually tried. I read through the FAQ and I tried using ...

  1. #1
    Unregistered
    Guest

    Clearing the screen in a dos console window...

    Hey all,

    WAIT! STOP! Don't flame me =P

    I've actually tried. I read through the FAQ and I tried using this code:

    void utilClearScreen(void)
    {
    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);
    return;
    }

    This method doesn't actually do anything for me. It doesn't clear my window at all, it executes but it doesn't do anything.

    And I've also made a loop that loops like 50 times and puts an "endl" but this looks really bad because then the new text is at the bottom of the console window which looks bad.

    Can anyone suggest any other ideas on how to clear the screen?

    Thanks guys!

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    in windows, system("CLS") or or the conio clear screen function if you have it.

  3. #3
    Unregistered
    Guest
    Those don't work for me either... I just don't know what to do..

    I'm using Visual C++ 6.0 btw.

  4. #4
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    who are you and what do you look like? what's your phone number? where do you live? are you home alone?
    TW,
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    int main()
    {
              printf("why hello there little boy!\n");
              system("PAUSE");
              system("CLS");
              printf("ouch!\n");
              return 0;
    }
    shutup...this works.

  5. #5
    Unregistered
    Guest
    Honestly, that DOES not work for me..

    However, I've fixed the problem. I did the 50 line sweep thing, then took that gotoXY code in the FAQ and updated the position to 0,0 for more writing.

    It works just fine.

  6. #6
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    well a search on the board might have brought up something like this...

    int i;
    for (i=26; i>= 0; --i)
    cout << '\n';


    and I find it hard to believe that

    system("cls");

    doesn't work

    Code:
    #include <stdlib>
    using namespace std;
    
    int main()
    {
       system ("cls");
       return 0;
    }
    compile that... open a console via Run by typing "command" in the run box if you are using win9x,me. Find your directory and type the name of the executable... you will see it clear the screen.

    or

    Code:
    #include <stdlib>
    #include <iostream>
    using namespace std;
    
    int main()
    {
    
       cout << "lalalalalalalalalalalalala\n";
       system ("pause");
       system ("cls");
       system ("pause");
       return 0;
    }
    using something like that, you can dbl click on the executable to see clear screen work.
    Last edited by Betazep; 02-14-2002 at 07:30 PM.
    Blue

  7. #7
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    >>>shutup...this works.

    Be nice... there is no reason to degrade someone else. We all make mistakes, and we all cannot figure things out from time to time without a little assistance.
    Blue

  8. #8
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    you sure you didn't drop your computer on the head when it was born?

  9. #9
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    maybe it's because you made a win32 project instead of a console project

  10. #10
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Dude, relax. This is programming!!!!! If he needs help, give it to him and don't flame him. Everyone has to learn sometime.

  11. #11
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    I'm not flaming him! so whats wrong with a few angry faces? so now I seem like I'm in a good mood!

  12. #12
    Señor Member
    Join Date
    Jan 2002
    Posts
    561
    If this isn't working, re-install Visual C++. If it still doesn't work, quit programming.

  13. #13
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    The system("cls") call or the function from the FAQ should have worked. Make sure all your text to output is sent from the buffer to the screen before clearing it. Does a console window clear itself when you open an empty one up, type some garbage and then try the CLS manually ?



    Xteria: Behave yourself, please.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  14. #14
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Code:
    #include <iostream>
    using std::cin;
    using std::cout;
    using std::endl;
    #include <windows.h>
    
    void utilClearScreen(void)
    {
    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);
    return;
    }
    int main(int argc, char *argv[])
    {
      char temp;
      cout << "Press to clear the screen (then wait 5 seconds)" << endl;
      for( ; ; ){
      cin.get(temp);
      if(temp == 'x')break;
      utilClearScreen();
      Sleep(5000);
      cout << "Press to clear the screen again ('x' then enter to quit)" << endl;
      }
      return 0;
    }
    That compiles fine as a console app on DevC++.......it should also compile fine with any other 32Compiler that can create windows apps (VC++, Borland Builder.....).

    Hopefully now with all the other options listed above (system("CLS")....etc) this will be the final "Clear the screen" post this board will ever see

    :: lives in hope ::

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 07:14 AM
  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. Adding colour & bmps to a Win 32 Window??
    By carey_sizer in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2004, 05:55 PM
  4. Maximizing a Console Window Full Screen
    By philvaira in forum Windows Programming
    Replies: 10
    Last Post: 08-13-2004, 02:27 AM
  5. Linux console window questions
    By GaPe in forum Linux Programming
    Replies: 1
    Last Post: 12-28-2002, 11:18 AM

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