how to get current console background and text colors?

前端 未结 3 1359
半阙折子戏
半阙折子戏 2021-01-01 19:06

I know how to set them (SetConsoleTextAttribute) but there isn\'t a GetConsoleTextAttribute to retrieve this information. On a unaffected console it should be int 7.

3条回答
  •  无人及你
    2021-01-01 19:36

    A quick grep of wincon.h shows that CONSOLE_SCREEN_BUFFER_INFO has a wAttributes member which is documented as "The attributes of the characters written to a screen buffer by the WriteFile and WriteConsole functions, or echoed to a screen buffer by the ReadFile and ReadConsole functions." This matches the description of SetConsoleTextAttribute: "Sets the attributes of characters written to the console screen buffer by the WriteFile or WriteConsole function, or echoed by the ReadFile or ReadConsole function." The structure is returned by GetConsoleScreenBufferInfo.

提交回复
热议问题