Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Color Attributes for SetConsoleTextAttribute()
- #define BLACK 0
- #define DARK_BLUE FOREGROUND_BLUE
- #define DARK_GREEN FOREGROUND_GREEN
- #define DARK_CYAN (FOREGROUND_GREEN | FOREGROUND_BLUE)
- #define DARK_RED FOREGROUND_RED
- #define DARK_MAGENTA (FOREGROUND_RED | FOREGROUND_BLUE)
- #define DARK_YELLOW (FOREGROUND_RED | FOREGROUND_GREEN)
- #define GRAY (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
- #define DARK_GRAY (FOREGROUND_INTENSITY)
- #define BLUE (FOREGROUND_BLUE | FOREGROUND_INTENSITY)
- #define GREEN (FOREGROUND_GREEN | FOREGROUND_INTENSITY)
- #define CYAN (FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY)
- #define RED (FOREGROUND_RED | FOREGROUND_INTENSITY)
- #define MAGENTA (FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY)
- #define YELLOW (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY)
- #define WHITE (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY)
- #include <windows.h>
- // Function prototype
- void SetColorRGB(int r, int g, int b);
- int main() {
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- // Example usage: Set to a color with full red and green components (yellow)
- SetColorRGB(255, 255, 0);
- printf("This text is in custom color based on RGB input.\n");
- // Reset to default attributes
- SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
- return 0;
- }
- // Function definition
- void SetColorRGB(int r, int g, int b) {
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- WORD color = 0;
- // Red component
- if (r > 128) color |= FOREGROUND_RED;
- // Green component
- if (g > 128) color |= FOREGROUND_GREEN;
- // Blue component
- if (b > 128) color |= FOREGROUND_BLUE;
- // Adjust intensity
- if (r > 192 || g > 192 || b > 192) color |= FOREGROUND_INTENSITY;
- SetConsoleTextAttribute(hConsole, color);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement