Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- console_window_colors_v2.c
- code of each color
- 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
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- #include <windows.h>
- void ClearConsoleToColors(int ForgC, int BackC)
- {
- WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
- ///Get the handle to the current output buffer...
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- ///This is used to reset the carat/cursor to the top left.
- COORD coord = {0, 0};
- ///A return value... indicating how many chars were written
- /// not used but we need to capture this since it will be
- /// written anyway (passing NULL causes an access violation).
- DWORD count;
- ///This is a structure containing all of the console info
- /// it is used here to find the size of the console.
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- ///Here we will set the current color
- SetConsoleTextAttribute(hStdOut, wColor);
- if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
- {
- ///This fills the buffer with a given character (in this case 32=space).
- FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
- FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count );
- ///This will set our cursor position for the next print statement.
- SetConsoleCursorPosition(hStdOut, coord);
- }
- return;
- } //ClearConsoleToColors()
- void SetColorAndBackground(int ForgC, int BackC)
- {
- WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);;
- SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
- return;
- } //SetColorAndBackground()
- int main(void)
- {
- int fColor, bColor;
- char str[100];
- //ClearConsoleToColors(15,15);
- for( bColor=0; bColor<=15; bColor++)
- {
- SetColorAndBackground(0,bColor);
- printf("B%-2d: ", bColor);
- for( fColor=0; fColor<=15; fColor++)
- {
- SetColorAndBackground(fColor,bColor);
- printf(" F%-2d", fColor);
- //sprintf(str, "\n This is a test. (f,b) = (%2d,%2d) ", fColor, bColor);
- //fputs(str, stdout); // print string str without '\n'
- }
- SetColorAndBackground(7,0);
- printf("\n");
- }
- SetColorAndBackground(7,0);
- return 0;
- } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement