code program Manipulasi warna teks console program

Posted: June 3, 2011 in Bahasa C++

#include
#include
#include

#define MAX 15
#define DELAY 10000000
#define FIRST 0
#define SECOND 25
#define THIRD 51
#define DEFAULT SetColor(7);

void SetColor(unsigned short);
void GotoXY(int, int);
void Delay(void);

int main(int argc, char *argv[]) {
size_t i, val = MAX;
for(i = 0; i < MAX; ++i) {
GotoXY(FIRST,i);
SetColor(i+1);
puts("Hello World!"); Delay();
}
for(i = 0; i < MAX; ++i) {
GotoXY(SECOND,i);
SetColor(i+2);
puts("Indo-Code.com"); Delay();
}
for(i = 0; i < MAX; ++i, –val) {
GotoXY(THIRD,i);
SetColor(val);
puts("C Programming"); Delay();
}
DEFAULT;
getch();
fflush(stdin);
return(0);
}

void SetColor(unsigned short color) {
HANDLE hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsoleOutput,color);
}

void GotoXY(int x, int y) {
HANDLE hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
COORD dwCursorPosition;
dwCursorPosition.X = x;
dwCursorPosition.Y = y;
SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
}

void Delay(void) {
int i = 0;
while(i < DELAY) {
++i;
}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s