WriteConsoleOutput

Giganews Newsgroups
Subject: WriteConsoleOutput
Posted by:  Paul Edwards (mutazil…@gmail.com)
Date: Tue, 4 Feb 2020

Hi folks.

Any idea why the below code is printing:

C:\devel\develop>winctest
168 9001
168 44
ret is 1

1 = success, yet doesn't write anything
visible to the console window?

Also, any idea why uemacs 4.0 source code
is using dwSize instead of dwMaximumWindowSize
so should be getting the wrong values, ie the
entire scrollback buffer instead of the actual
screen size?

Thanks. Paul.

#include <stdio.h>

#include <windows.h>

int main(void)
{
    HANDLE hConsoleOutput;
    static CONSOLE_SCREEN_BUFFER_INFO csbi;
    CHAR_INFO mybuf[16];
    int x;
    int y;
    COORD sz;
    COORD coord;
    SMALL_RECT rect;
    int ret;

    hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hConsoleOutput, &csbi);
    printf("%d %d
", (int)csbi.dwSize.X, (int)csbi.dwSize.Y);
    printf("%d %d
", (int)csbi.dwMaximumWindowSize.X, (int)csbi.dwMaximumWindowSize.Y);
    for (x = 0; x < 16; x++)
    {
        mybuf[x].Char.AsciiChar = 'Z';
        mybuf[x].Attributes = 0x7;
    }
    sz.X = 1;
    sz.Y = 16;
    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);
    printf("ret is %d
", ret);
    return (0);
}

Replies