// con01.c #include #include #include int main(void) { HANDLE hStdout; WORD wAttributes; CONSOLE_SCREEN_BUFFER_INFO csbi;//構造体です hStdout = GetStdHandle(STD_OUTPUT_HANDLE); //hStdoutのコンソールスクリーンバッファ情報をcsbiに取得 GetConsoleScreenBufferInfo(hStdout, &csbi); wAttributes = FOREGROUND_GREEN; SetConsoleTextAttribute(hStdout, wAttributes); printf("緑です wAttributes = %d\n", wAttributes); wAttributes = FOREGROUND_RED; SetConsoleTextAttribute(hStdout, wAttributes); printf("赤です wAttributes = %d\n", wAttributes); wAttributes = wAttributes | BACKGROUND_BLUE | BACKGROUND_INTENSITY; SetConsoleTextAttribute(hStdout, wAttributes); printf("バックを青の強調にしました wAttributes = %d\n", wAttributes); //元のテキスト状態に戻す SetConsoleTextAttribute(hStdout, csbi.wAttributes); //何かキーを打つと終了 _getch(); return 0; }