如何获取当前控制台背景和文本颜色? [英] how to get current console background and text colors?

查看:433
本文介绍了如何获取当前控制台背景和文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何设置它们(SetConsoleTextAttribute),但没有一个GetConsoleTextAttribute来检索这个信息。在未受影响的控制台上,它应该是int 7。

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.

问题是,当从设置文本颜色的程序退出时,

The problem is that when exiting from a program that sets the text color it stays the same for the time given window runs, and I cannot assume that user hasn't set the colors to his custom liking.

推荐答案

<$ c $的快速grep c> wincon.h 显示 CONSOLE_SCREEN_BUFFER_INFO 有一个 wAttributes 成员, =http://msdn.microsoft.com/en-us/library/windows/desktop/ms682093%28v=VS.85%29.aspx =nofollow>记录为属性通过WriteFile和WriteConsole函数写入屏幕缓冲区的字符,或者通过ReadFile和ReadConsole函数回显到屏幕缓冲区。这与的描述符合 SetConsoleTextAttribute :设置由WriteFile或WriteConsole函数写入控制台屏幕缓冲区或通过ReadFile或ReadConsole函数回显的字符的属性。结构由 GetConsoleScreenBufferInfo 返回。

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.

这篇关于如何获取当前控制台背景和文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆