SetConsoleTextAttribute设置颜色后的恢复

来源:互联网 发布:淘宝买电影票总么赚钱 编辑:程序博客网 时间:2024/05/03 19:28

1、

#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <string.h>#include <stdlib.h>#include <windows.h>int main(){HANDLE handle;//WORD wOldColorAttrs;//CONSOLE_SCREEN_BUFFER_INFO csbiInfo;handle = GetStdHandle(STD_OUTPUT_HANDLE);//GetConsoleScreenBufferInfo(handle, &csbiInfo);//wOldColorAttrs = csbiInfo.wAttributes;SetConsoleTextAttribute(handle, FOREGROUND_GREEN |                                FOREGROUND_INTENSITY);puts("yes");SetConsoleTextAttribute(handle, FOREGROUND_RED |FOREGROUND_GREEN |FOREGROUND_BLUE);//SetConsoleTextAttribute(handle, wOldColorAttrs);puts("yes");return 0;}


2、

#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <string.h>#include <stdlib.h>#include <windows.h>int main(){HANDLE handle;WORD wOldColorAttrs;CONSOLE_SCREEN_BUFFER_INFO csbiInfo;handle = GetStdHandle(STD_OUTPUT_HANDLE);GetConsoleScreenBufferInfo(handle, &csbiInfo);wOldColorAttrs = csbiInfo.wAttributes;SetConsoleTextAttribute(handle, FOREGROUND_GREEN |                                FOREGROUND_INTENSITY);puts("yes");/*SetConsoleTextAttribute(handle, FOREGROUND_RED |FOREGROUND_GREEN |FOREGROUND_BLUE);*/SetConsoleTextAttribute(handle, wOldColorAttrs);puts("yes");return 0;}

BOOL WINAPI GetConsoleScreenBufferInfo(
  _In_   HANDLE hConsoleOutput,
  _Out_  PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
);
GetConsoleScreenBufferInfo function:Retrieves information about the specified console screen buffer.

原创粉丝点击