zoukankan
html css js c++ java
VC++中控制控件台字体颜色(转)
#include
"
windows.h
"
#include
<
iostream
>
#include
<
string
>
#include
"
head.h
"
using
namespace
std;
enum
clr
{ FB
=
FOREGROUND_BLUE,
FG
=
FOREGROUND_GREEN,
FR
=
FOREGROUND_RED,
FI
=
FOREGROUND_INTENSITY,
BB
=
BACKGROUND_BLUE,
BG
=
BACKGROUND_GREEN,
BR
=
BACKGROUND_RED,
BI
=
BACKGROUND_INTENSITY }
;
class
color
{
public
:
explicit
color( WORD wAttributes
=
getcurrentvalue_() ) : wAttributes_(wAttributes)
{
}
WORD getvalue(
void
)
const
{
return
wAttributes_;
}
private
:
static
WORD getcurrentvalue_(
void
)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
::GetConsoleScreenBufferInfo( ::GetStdHandle(STD_OUTPUT_HANDLE),
&
csbi );
return
csbi.wAttributes;
}
WORD wAttributes_;
}
;
const
color setcolor( WORD wAttributes )
{
::SetConsoleTextAttribute( ::GetStdHandle(STD_OUTPUT_HANDLE), wAttributes );
return
color(wAttributes);
}
const
color setcolor( color clrAttributes )
{
return
setcolor( clrAttributes.getvalue() );
}
ostream
&
operator
<<
( ostream
&
os,
const
color
&
wc )
{
return
os;
}
;
istream
&
operator
>>
( istream
&
os,
const
color
&
wc )
{
return
os;
}
;
class
position
{
public
:
position( SHORT row, SHORT col ) : row_(row), col_(col)
{
}
position(
const
position
&
pos
=
getcurrentvalue_() ) : row_(pos.row_), col_(pos.col_)
{
}
SHORT getrow(
void
)
const
{
return
row_;
}
SHORT getcol(
void
)
const
{
return
col_;
}
private
:
static
const
position getcurrentvalue_(
void
)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
::GetConsoleScreenBufferInfo( ::GetStdHandle(STD_OUTPUT_HANDLE),
&
csbi );
return
position( csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y );
}
SHORT row_, col_;
}
;
const
position setpos( SHORT row, SHORT col )
{
COORD coord
=
{ col, row }
;
::SetConsoleCursorPosition( ::GetStdHandle(STD_OUTPUT_HANDLE), coord );
return
position( row, col );
}
const
position setpos( position pos )
{
return
setpos( pos.getrow(), pos.getcol() );
}
ostream
&
operator
<<
( ostream
&
os,
const
position
&
wc )
{
return
os;
}
;
istream
&
operator
>>
( istream
&
os,
const
position
&
wc )
{
return
os;
}
;
int
_tmain(
int
argc, _TCHAR
*
argv[])
{
using
namespace
std;
color oldcolor;
cout
<<
setcolor(FG)
<<
"
输入一段文字吧
"
<<
endl;
//
cout << setpos(1,15) << setcolor(FB) << "输入一段文字吧" << endl;
string
s;
cin
>>
setpos(
5
,
10
)
>>
setcolor(FI)
>>
s;
position curpos;
cout
<<
setcolor(oldcolor)
<<
"
*这里是
"
<<
curpos.getrow()
<<
"
行
"
<<
curpos.getcol()
<<
"
列
"
<<
endl;
setcolor( oldcolor );
static
int
a;
cout
<<
a
<<
endl;
getchar();
return
0
;
}
查看全文
相关阅读:
VS2005中的WebApplication和WebSite
CodeFile 与 CodeBehind 的区别
vs2005默认浏览器(IE)灵异事件
杭电OJ第4252题 A Famous City
湘大OJ第1490题 Generating Random Numbers
中南OJ 2012年8月月赛 B题 Barricade
中南OJ 2012年8月月赛 H题 Happy watering
杭电OJ第4245题 A Famous Music Composer
中南OJ 2012年8月月赛 I题 Imagination
杭电OJ第4256题 The Famous Clock
原文地址:https://www.cnblogs.com/myopq/p/581548.html
最新文章
JZ038二叉树的深度
centOS搭建本地yum
为什么说linux是开源不开放, android是开源又开放.
http操作
[unix c]关于FOLK和PRINTF()的一个小问题
The Java Data Mining API[转]
如意才一年......
理解
half 郁闷 reserved
圣经一段
热门文章
[复习计划]IMS5024
随便谈谈
"We are Australian"
一个开源的ETL工具
将Excel内容导入数据库(ASP.NET/C#)
VS2005灵异事件2“缺少引用”以及“断点无法命中”
将Dataset数据导出到Excel中(ASP.NET/C#)
关于vs2005的“EnableEventValidation”
ASP.NET打印
仿Excle公式
Copyright © 2011-2022 走看看