CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2008
    Posts
    1

    Console window clearing.

    I am making a C++ console Blackjack game, and I want it to clear a line, without clearing the whole thing (like CLS)

    Is there a reativly simple way to do this?

  2. #2
    Join Date
    Nov 2003
    Posts
    1,902

    Re: Console window clearing.

    Tutorial on Windows OS console API: http://www.adrianxw.dk/SoftwareSite/...Consoles1.html

    You'll learn a few tricks - including what you're looking for.

    gg

  3. #3
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    Re: Console window clearing.

    You can call this function to do it. Make sure you include <windows.h>
    Code:
    void clrscr()
    {
        COORD coord_screen = { 0 , 0 };
        CONSOLE_SCREEN_BUFFER_INFO csbi;
        DWORD chars_written , con_size;
        // get output handle to console
        HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
        // work out console size
        GetConsoleScreenBufferInfo(hConsole, &csbi);
        con_size = csbi.dwSize.X * csbi.dwSize.Y;
        // fill with blanks
        FillConsoleOutputCharacter(hConsole, TEXT(' '), con_size, coord_screen, &chars_written);
        GetConsoleScreenBufferInfo(hConsole, &csbi);
        FillConsoleOutputAttribute(hConsole, csbi.wAttributes, con_size, coord_screen, &chars_written);
        // move cursor to top left corner
        SetConsoleCursorPosition(hConsole, coord_screen);
    }

  4. #4
    Join Date
    Jan 2008
    Posts
    178

    Re: Console window clearing.

    Avoid newbies "tutorials"
    Read MSDN, where everything is there. see Console apis reference

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured