Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <iostream>
- /* irodelta.cpp sets a new console color without modifying previous text */
- void setConsoleColour(unsigned short colour)
- {
- static const HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
- std::cout.flush();
- SetConsoleTextAttribute(hOut, colour);
- }
- int main(int argc, char **argv)
- {
- if (argc <= 1)
- {
- if (argv[0])
- std::cout << "Usage: " << argv[0] << " <1 or 2-digit hexadecimal number (FOREGROUND BACKGROUND)>" << '\n';
- else
- std::cout << "Usage: <win32_irodelta.exe> <1 or 2-digit hexadecimal number (FOREGROUND BACKGROUND)>" << '\n';
- std::exit(1);
- }
- char *input = argv[1];
- char a = input[0];
- char b = input[1];
- unsigned short foreground = 0; // 0-15
- unsigned short background = 0; // multiple of 16
- if (a>=65 && a<=70)/*ASCII for A-F -> 10-15*/{
- foreground = a-55;
- } else if (a>=97 && a<=102)/*ASCII for a-f -> 10-15*/{
- foreground = a-87;
- } else if (a>=48 && a <= 57)/*ASCII for 0-9*/{
- foreground = a-48;
- }
- if (b>=65 && b<=70){
- background = (b-55)*16;
- } else if (b>=97 && b<=102){
- background = (b-87)*16;
- } else if (b>=48 && b <= 57){
- background = (b-48)*16;
- }
- if (background!=(foreground*16)){
- setConsoleColour(foreground | background);
- } else {
- std::cout << "Error: First argument cannot have same foreground and background" << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement