clearing screen

Giganews Newsgroups
Subject: clearing screen
Posted by:  muta.…@gmail.com (mutazil…@gmail.com)
Date: Tue, 20 Oct 2020

I (believe I) have figured out the behavior of GetConsoleScreenBufferInfo

    hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hConsoleOutput, &csbi);
    printf("size char_info is %d
", sizeof(CHAR_INFO));
    printf("%d %d
", (int)csbi.dwSize.X, (int)csbi.dwSize.Y);
    printf("%d %d
", (int)csbi.dwMaximumWindowSize.X, (int)csbi.dwMaximumWindowSize.Y);
    printf("%d %d
", (int)csbi.srWindow.Right, (int)csbi.srWindow.Bottom);

The window sizes (rows) include the size of the
scrollback buffer. Except for the "Maximum" -
that reflects the actual screen size.

Regardless, when I attempt to write to row 16
like this:

    sz.X = 16;
    sz.Y = 1;
    coord.X = 0;
    coord.Y = 0;
    rect.Left = 1;
    rect.Top = 10; /* was 10 */
    rect.Right = 17; /* was 17 */
    rect.Bottom = 10; /* was 10 */
    ret = WriteConsoleOutput(hConsoleOutput,
                      mybuf,
                      sz,
                      coord,
                      &rect);

it does actually write to row 16, but it is row 16
of the scrollback buffer, so it's not actually
visible on my screen.

If I run "cls" first, then everything is reset and
everything works as I want.

My question is - is there a call to clear the
screen? Or some other approach?

Besides system("cls");

Thanks. Paul.

Replies