1\鼠标右键点击控制台窗口标题,菜单"属性"在可以改变前景色和背景色.
2\程序中改变,我找了很久,没找到改变背景的方法,只有关于文字的背景色和前景色控制的方法:
代码如下:
HANDLE hConsole;
WORD ForeColor = 0;
WORD BackColor;
WORD wAttributesOld;
CONSOLE_SCREEN_BUFFER_INFO csbi;
// ** Open the current console input buffer.
if( ( hConsole = CreateFile(
"CONOUT$", GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L) )
== (HANDLE) -1 ) {
printf("\nError: Unable to open console.\n");
return( -1 );
}
printf("\n");
// ** Get and Save information on the console screen buffer.
GetConsoleScreenBufferInfo( hConsole, &csbi );
wAttributesOld = csbi.wAttributes;
// ** Display different backgrounds.
for( BackColor = 0; BackColor < 8 ; BackColor++ ) {
SetConsoleTextAttribute( hConsole, (WORD) ( (BackColor << 4) |
ForeColor) );
printf(" XxXxXx ");
}
// ** Restore the foreground and background color attribute.
SetConsoleTextAttribute( hConsole, wAttributesOld );
http://www.
这是一个关于控件台界面编程的文章.