简体   繁体   English

如何使用 C 通过坐标等改变控制台在特定点的背景颜色?

[英]How to change the background color of the console at a specific point by coordinates or so using C?

I need to change color of a certain cell in the console without printing any character with a given color there using the SetConsoleTextAttribute function or similar methods.我需要更改控制台中某个单元格的颜色,而不使用SetConsoleTextAttribute function 或类似方法在控制台中打印任何具有给定颜色的字符。

FillConsoleOutputAttribute function Sets the character attributes for a specified number of character cells, beginning at the specified coordinates in a screen buffer. FillConsoleOutputAttribute function 为指定数量的字符单元设置字符属性,从屏幕缓冲区中的指定坐标开始。

BOOL WINAPI FillConsoleOutputAttribute(
  _In_  HANDLE  hConsoleOutput,
  _In_  WORD    wAttribute,
  _In_  DWORD   nLength,
  _In_  COORD   dwWriteCoord,
  _Out_ LPDWORD lpNumberOfAttrsWritten
);

if the number of character cells whose attributes are to be set extends beyond the end of the specified row in the console screen buffer, the cells of the next row are set.如果要设置属性的字符单元的数量超出控制台屏幕缓冲区中指定行的末尾,则设置下一行的单元。 If the number of cells to write to extends beyond the end of the console screen buffer, the cells are written up to the end of the console screen buffer.如果要写入的单元格数量超出控制台屏幕缓冲区的末尾,则单元格将被写入控制台屏幕缓冲区的末尾。

The character values at the positions written to are not changed.写入位置的字符值不变。

This API is not recommended and does not have a specific virtual terminal equivalent.不推荐使用此 API,并且没有特定的虚拟终端等效项。 Filling the region outside the viewable window is not supported and is reserved for the terminal's history space.不支持填充可视 window 之外的区域,为终端的历史空间保留。 Filling a visible region with new text or color is performed through moving the cursor, setting the new attributes, then writing the desired text for that region, repeating characters if necessary for the length of the fill run.使用新文本或颜色填充可见区域是通过移动 cursor、设置新属性、然后为该区域写入所需文本、如果需要重复填充运行长度的字符来执行的。 Additional cursor movement may be required followed by writing the desired text to fill a rectangular region.可能需要额外的 cursor 移动,然后写入所需的文本以填充矩形区域。 The client application is expected to keep its own memory of what is on the screen and is not able to query the remote state.客户端应用程序应保留其自己的 memory 屏幕上的内容,并且无法查询远程 state。 More information can be found in classic console versus virtual terminal documentation.更多信息可以在经典控制台与虚拟终端文档中找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM