woaidongmao

文章均收录自他人博客,但不喜标题前加-[转贴],因其丑陋,见谅!~
随笔 - 1469, 文章 - 0, 评论 - 661, 引用 - 0
数据加载中……

VC控制台编程设置字体颜色

windows 有提供一套conosle API来读写console缓存,字体、颜色、创建console等的, 但颜色格式没有找到任意颜色的接口,只能用系统自定义几种颜色。不过在命令行窗体可以看到系统是支持完全自定义 红 绿蓝颜色分量的的颜色的,不知道系统为什么自己不开放,好像vista里面的api有支持了,不过MSDN也不做详细解释。

#include "stdafx.h"
#include <windows.h>

using namespace std ;
int _tmain(int argc, _TCHAR* argv[])
{  
HANDLE hConsole;
int k;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
// you can loop k higher to see more color choices
for(k = 1; k < 255; k++) {  
   // pick the colorattribute k you want   
   SetConsoleTextAttribute(hConsole, k);  
   cout << k << " I want to be nice today!" << endl;
}  
cin.get();   // wait
return 0;
}

VC控制台编程设置字体颜色 - widebright - widebright的个人空间

posted on 2011-08-10 17:08 肥仔 阅读(860) 评论(0)  编辑 收藏 引用 所属分类: MFC存档


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理