问题
I'm trying to set the background and foreground colors of the Windows command line console by using GetConsoleScreenBufferInfoEx and SetConsoleScreenBufferInfoEx .
I'm doing it in Python, by using wintypes, and sofar it works.
But there's something odd happening: the window shrinks a little at every call.
This is how the calling code looks like:
def GetConsoleScreenBufferInfoEx(handle):
csbi = CONSOLE_SCREEN_BUFFER_INFOEX() # a structure
csbi.cbSize = 96 # needs to be set
success = _GetConsoleScreenBufferInfoEx( # just a wrap
handle, byref(csbi))
return csbi
csbi = GetConsoleScreenBufferInfoEx(handle)
csbi.wAttributes = color
SetConsoleScreenBufferInfoEx(csbi)
Now, everytime I change the color, the window also shrinks.
I can fix it by adding
csbi.srWindow.Right += 1 # otherwise the window will shrink
csbi.srWindow.Bottom += 1
before SetConsoleScreenBufferInfoEx(csbi)
The CONSOLE_SCREEN_BUFFER_INFOEX structure is defined as expected, no values are altered there.
It looks like the GetConsoleScreenBufferInfoEx function returns the last index, so when the window width is 80 csbi.srWindow.Right is 79. But when passing the same value to SetConsoleScreenBufferInfoEx it is interpreted as width.
Is this behaviour normal or is there an error?
来源:https://stackoverflow.com/questions/37849801/why-does-the-console-window-shrink-when-using-getconsolescreenbufferinfoex-in-wi