SetConsoleScreenBufferInfoEx … bug?

ⅰ亾dé卋堺 提交于 2019-12-07 09:56:45

问题


Each time I run this code ( on Win7) the console gets 1 character smaller in both directions.

int wmain( INT argc, WCHAR **argv )  
{  
    CONSOLE_SCREEN_BUFFER_INFOEX csbi;  
    csbi.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);  
    GetConsoleScreenBufferInfoEx(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);  
    wprintf(L"Window: %u x %u\n", csbi.srWindow.Right - csbi.srWindow.Left + 1, csbi.srWindow.Bottom - csbi.srWindow.Top + 1);  
    SetConsoleScreenBufferInfoEx(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);  
    return 0;  
}

I doubt that's expected behavior. Is it documented? Is it any better in newer versions of Windows? Here's a clip of running it a few times.

p:\test\release> test.exe
Window: 99 x 41

p:\test\release> test.exe
Window: 98 x 40

p:\test\release> test.exe
Window: 97 x 39


回答1:


Long standing "won't fix" bug in the Windows console API. You just need to do what everyone else does, and increment the window.Bottom and window.Right after reading it.

GetConsoleScreenBufferInfoEx(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)
++csbi.srWindowBottom;
++csbi.srWindowRight;


来源:https://stackoverflow.com/questions/35901572/setconsolescreenbufferinfoex-bug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!