|
Memberlist | Forum Rules | Search | Today's Posts | Mark Forums Read |
Search Forums: | Click here to use Advanced Search |
![]() |
|
Thread Tools | Display Modes |
![]() |
#1 | ||
Join Date: Oct 2004
Location: Opole, Poland
Posts: 14,276
|
![]() I was messing with some things yesterday and got somewhat annoyed at the fact that while there is a way to change text and background color in a Windows console enviroment (for specific parts of the text rather than the whole thing at once), it's slightly unintuitive for the end user.
So, I cooked up a custom include with a few functions and definitions that make the color-changing a breeze: (Attached as textcolor.h ) Note that negative argument values are used to reset the setting to default. |
||
![]() ![]() |
|
![]() |
#2 | ||
![]() ![]() ![]() ![]() ![]() Join Date: May 2009
Location: Abo Tanga, Afghanistan
Posts: 28
|
![]() Some incomplete attempt to make it into a iomanipulator, didn't try if it compiles on Windows as I wrote it on Linux. Use it only with std::cout!
Code:
#include <iosfwd> #include <windows.h> class colors { private: int val; friend std::ostream& operator<< (std::ostream& stream, colors const input) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), input.val); return stream; } public: colors(int a) { val = a < 0 ? 7 : (a % 256); } colors (int a, int b) { a = a < 0 ? 0 : (a % 16); b = b < 0 ? 7 : (b % 16); val = a * 16 + b; } enum { BLACK,BLUE,GREEN,CYAN,RED }; }; Put directly below the above "header" Code:
#include <iostream> int main () { std::cout << "test " << colors(257)<< "test2" << colors(colors::BLUE,10) << "test3" << std::endl; return 0; } Last edited by Peter; 14-04-2010 at 07:08 PM. |
||
![]() ![]() |
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
DOSBox, The Random Color Glitch | The_Lemming | Troubleshooting | 14 | 03-07-2012 08:33 PM |
champions of krynn no sound, nu-rave color | lord galen | Troubleshooting | 6 | 12-06-2009 02:16 PM |
Red Baron (256-color VGA version) | Miles | On site | 8 | 31-07-2008 12:59 PM |
Color Lines | troop18546 | Approved Requests | 3 | 13-09-2007 08:49 PM |
Color Problem With Old Games | Guest | Tech Corner | 7 | 29-08-2006 06:44 PM |
Thread Tools | |
Display Modes | |
|
|
||
  |