C++ and Coloured Text

I'm trying implementing colour text into a program, except my current method only has 16 different colours (which isn't enough).

With a little research, I stumbled upon this website: http://www.adp-gmbh.ch/win/programming/graphic/color.html

My question is, how the hell do I use it?

1
2
3
4
5
6
...
// wondering what goes where
cout << "Testing coloured text...\n";
cin.get();
return 0;
...


Or, is there an alternative where I can utilize more than my currently limited 16 colours?
Last edited on
The COLORREF is not useful for console programming. Also, you are indeedy stuck with 16 colors on the console.

For playing with colors in the Windows Console, see one or more of the following:

Class for handling colors
http://www.cplusplus.com/forum/general/48596/#msg264748

Simple example of using SetConsoleTextAttribute()
http://www.cplusplus.com/forum/general/9974/#msg46705

And a simple explanation
http://www.cplusplus.com/forum/beginner/52280/#msg283674

Good luck!
Thanks for the response Duoas, was hoping for some crazy colour customization but I suppose the 16 colours I have available to me will have to suffice.
It seems like you're severely limited when you think about only 16 colors, but in all honesty, there is so much you can do with just the 16 colors. I know everyone is probably tired of hearing about it, but that's how I was able to do my tetris game and have it actually look like tetris. Every shape had a unique color and i believe my board array was the value of the color to display. It worked really well and I had gotten a lot of compliments about it, but sadly, it wasn't perfect as I was young and naive.

I might get around to redesigning it again knowing what I know since it was a very nice looking game.

@Duoas
Do you know of something similar for POSIX systems? Whenever I get around to doing this again, I want to make a standard, or atleast standard workarounds on getting it to work on every common system. I have read a lot of your threads on the getch() function and other non standard ways of doing things. You have helped me learn a great deal and learned the proper way to do things. I'm now satisfied that once I learn more about POSIX systems, I can program just about anything for any system.

I greatly appreciate your contribution to the community.
Fwiw, you get more than 16 colors if you leave the console. :P
Also it'd be much easier to make a tetris clone outside of the console.
It was all I knew back then, and I completely understand that it's easier using a GUI, but I think it's very interesting creating the tetris like game inside of the console. I know it's not designed for it, and it isn't suggested either, but it does show that a lot is available to be done.

BTW, I'm still looking for a good set of libraries for a GUI. I downloaded FLTK and QT, but neither of which I actually like. I want a GUI more for Forms and Buttons and I know some WIN32 API, but I want something that is the same on each system, but it's not required. I also dislike the libraries because to have someone else test the code, they must also have the libraries, and the same version or higher incase you use something that isn't in an older version.

I find sticking with standard C++ is a better way to go until I find a great library that can create simple GUIs with easy code, but still have the options for more advanced GUIs. I've also found that the documentation on some of the stuff isn't very clear and reading about ResidentBiscuits issues over at SFML forums have turned me away from there.

I was interested in GLUT but noticed it hasn't been updated in some time. I was also consider a few other libraries, but I feel the options are limited. What are your suggestions?
I still want to finish an article on doing things in the console, including colors. Messing with colors in *nix is actually one of the things more obnoxious to do, and you don't have the same colorspace guarantees as you do on Windows, so you have to be more careful to make your application adapt to color availability.
Volatile Pulse wrote:
I know everyone is probably tired of hearing about it, but that's how I was able to do my tetris game and have it actually look like tetris.
Woah, I'm gonna try to do it! Anyways there is an article here on cplusplus.com, besides threads. This is it: http://www.cplusplus.com/articles/2ywTURfi/

Almost-OT:
I also made a Multi-function console, which enabled use of colours, console-clearing, position-based text, but since no one did care (as almost everyone now doesn't use Consoles anymore) I stopped continuing it so much and focused on other projects.
It's a shoddy Article. (The author is a newbie and misses quite a few points. Kudos though for wanting to share stuff he learned.) My class here is superior in a number of ways:
http://www.cplusplus.com/forum/general/48596/#msg264748

If you really want to directly mess with colors in *nix right now, check out the following:
http://www.cplusplus.com/forum/general/11032/#msg52049
http://www.cplusplus.com/forum/general/11032/2/#msg52617

Hope this helps.
Volatile Pulse wrote:
I downloaded FLTK and QT, but neither of which I actually like.I want a GUI more for Forms and Buttons and I know some WIN32 API, but I want something that is the same on each system, but it's not required.


I am not sure what you meant by this - Qt does buttons ( and all kinds of controls) & forms, and it is one source tree for a multude of OS's including Windows.

Qt is widely used, and now you can ceate apps for mobile devices as well.

A downside is that Qt 5.0 is the last version to be developed by Nokia.

As of gui theres Gtk+ (gtkmm for C++)
@Duoas
I believe I'll wait for your release. I only plan on doing it, so I'm in no rush. Maybe once the time gets closer to actually doing, I'll read more into it. I do suggest creating an article as more of a reference for general things. I find I jump through so many google searches and forum pages to find what I'm looking for. I also hate having to direct people to other sites because the references here are outdated. Have you found anything good for new C++11 features? More specifically, std::threads?

@TheIdeasMan
I know QT offers everything I was looking for, but it didn't feel/look smooth when I was reading over the tutorials. Maybe I'll give it another shot, but the one code I typed up for it, didn't work like I had expected and got frustrated and gave up.

@EssGeEich
I saw that, and I might look into it somemore. I know there was a reason why I didn't download it yet, but can't remember. Possibly outdated?

@Phil123
Sorry for taking over your thread. I hope you're learning a lot though =)
Alas, I have to admit that I've been "planning" to write an article for a couple of years now... In the meantime I just point people to those few posts I've already made.
@Phil123
Sorry for taking over your thread. I hope you're learning a lot though =)


Haha, no problem, I've got a lot to learn so I really appreciate this community. And yeah, I realized that the dark yellow "kind of" looks like a brown, so I can use it for that. (If anyone's curious, this is for my text based RPG I've been working on as a fun/learning project). Implementing colour text into it took up quite a few lines (I'm OCD with my formatting, what can I say), so I'm probably up in the 1600s now (including comment lines of course) and I'm not even done :)
Sorry for my late reply, but probably the reason you didn't download it is because of dependencies. Anyways in the Windows installer every needed thing is included. About gtkmm, i don't know.
Topic archived. No new replies allowed.