How do I change console background color?

So this code
1
2
3
#include <windows.h>

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0); //replace the 0 with a number for the color you want 


will give me the text color green. But, what can I add to this line to change the background color of the console?

Thanks :)
Try running this:
1
2
3
4
5
6
7
8
9
10
11
12
13
void allColours()
{
	using namespace std;

	cin.get();

	for (int colour = 0x00; colour <= 0xff; colour ++)
	{
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),colour);
		cout << "Using colour:" << colour << endl;
		cin.get();
	}
}


Essentially you'll see that if you set the color anywhere between 0 and 15 (0x00 and 0x0f), then you are changing the text color. If you enter a colour anywhere between 16 and 31, you will have the same text colors, but with a different background.

I smell someone wasting time and effort on learning something they shouldn't.

Obligatory link:

http://cplusplus.com/forum/articles/28558/
Actually, I like the suggestion because there will be times in the future where you cannot find a help page to assist you. Recently I wanted to learn about CardGames.dll, which is a Windows 7 version of Cards.dll. I wanted my programs to be upgraded for the new driver instead of always sending the old driver out with my programs. Well, there was not anything out there to help me, even from Microsoft so I created a program which went through each UINT and tested to see if there was a picture in there to represent the bitmap. It worked perfectly in cards.dll but it did not work with CardGames.dll which allowed me to learn that the pictures inside were in fact not bitmaps.

It may be harder the way he suggested, but you learn more which is more valuable because you save time later for more complicated problems.
I'm not sure I understand how that relates.
Thank you Stewbond, for the answer :). And thanks guys for your input.

Disch, I've read the post that you created regarding console programming to game programming.



Like, what you've wrote really got me. But the thing is, I don't know the concepts about "libs". I was trying to research more about that yesterday but the subject seems very confusing.

It's like, you have to "download third party libraries" and supposedly there are many third party libraries?

How would we even know which one is reliable or not? How do we know if they are professionally made or not?

Also, the most important question is, after we "download" the lib file, how do we even integrate it in our IDE's? I hear we have to link it or something.

If only there was a tutorial for this. I can't find anywhere online that talks about "How To" download and install libs, APIs, and etc. I don't even know what an API is. I searched online and it said it was an "Application Programming Interface". I don't even know what that exactly is but I do know it's supposed to help you applications. I don't know how to install it nor do I know any files of it or if its even a file at all, or a lib. And what is a DLL?

DLL, Libs, APIs, and anything similar to that is like outer space for a beginner like me. How can I learn more about these things? I really want to add sounds, graphics, etc to my programs, but where do I start?
Topic archived. No new replies allowed.