-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwindows.c
45 lines (41 loc) · 893 Bytes
/
windows.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <dos.h>
#include <dir.h>
/*
Color List:
Name | Value
|
Black | 0
Blue | 1
Green | 2
Cyan | 3
Red | 4
Magenta | 5
Brown | 6
Light Gray | 7
Dark Gray | 8
Light Blue | 9
Light Green | 10
Light Cyan | 11
Light Red | 12
Light Magenta| 13
Yellow | 14
White | 15
*/
void setColor(int color) {
WORD colorWord;
HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO buffer;
if(GetConsoleScreenBufferInfo(output, &buffer)) {
colorWord = (buffer.wAttributes & 0xF0) + (color & 0x0F);
SetConsoleTextAttribute(hStdOut, colorWord);
}
}
int main(void) {
setColor(4);
printf("This text a sample text with Red color!\n");
getch(); // C++: cin.get();
return 0;
}