Created
April 26, 2010 18:26
-
-
Save CrBoy/379686 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void gotoxy(int x, int y){ | |
HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE ); | |
COORD coord={x, y}; | |
SetConsoleCursorPosition(hConsole, coord); | |
} | |
void setcolor(const char *fore, const char *back){ | |
WORD type=0; | |
while(*fore!='\0'){ | |
switch(*fore){ | |
case 'r': | |
case 'R': | |
type |= FOREGROUND_RED; | |
break; | |
case 'g': | |
case 'G': | |
type |= FOREGROUND_GREEN; | |
break; | |
case 'b': | |
case 'B': | |
type |= FOREGROUND_BLUE; | |
break; | |
case '+': | |
type |= FOREGROUND_INTENSITY; | |
} | |
fore++; | |
} | |
while(*back!='\0'){ | |
switch(*back){ | |
case 'r': | |
case 'R': | |
type |= BACKGROUND_RED; | |
break; | |
case 'g': | |
case 'G': | |
type |= BACKGROUND_GREEN; | |
break; | |
case 'b': | |
case 'B': | |
type |= BACKGROUND_BLUE; | |
break; | |
case '+': | |
type |= BACKGROUND_INTENSITY; | |
} | |
back++; | |
} | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),type); | |
}//使用方法:setcolor("rgb+", "rgb+"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __WIN32_CONSOLE_H__ | |
#define __WIN32_CONSOLE_H__ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <windows.h> | |
void gotoxy(int x, int y); //在console mode的緩衝區中移動 | |
void setcolor(const char* fore="rgb", const char* back=""); //設定console游標繪出的文字與背景顏色 | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
這是我大一時候的作品,setcolor()的部份也許寫得還不夠好,若日後有機會希望再改進!