Cuple questions

Hello C++ commuity.

I'm new to programming and I've learned allot in the past few weeks. Right now I'm in the process of creating my own program. But I am stuck on a couple of issues I can't find any help on.

My two questions are...

How do I change the background color of a Win32 console app?
then..

How can I clear my previous text that appears when you start the program. I understand that's hard to understand. But what I'm trying to explain here is, that I'm using a switch command to give the user a menu to choose from. But I can't figure how to clear everything after the user has made his choice..

Thanks,
-Jolt.
Last edited on
Well...you can set the background specifically in the window properties...but I don't think that's what you want. If you want to set it just for your program...you can use SetConsoleAttribute() (i think).

For clearing text, you can use "system("cls");" if you don't might getting yelled at for crappy code practices hehe...Otherwise, you could output a bunch of new lines in order to push the other text off the screen.
Clear the screen
http://www.cplusplus.com/forum/beginner/1988/page3.html#msg10830

Change bg color
1
2
3
4
5
6
7
8
9
#include <windows.h>

...

HANDLE hcout = GetStdHandle( STD_OUTPUT_HANDLE );

...

SetConsoleTextAttribute( hcout, color );

The color value is the same as for EGA/VGA 16-color text modes, except that the high bits always signify intensity. The low nibble is foreground. The high nibble is background.

1 blue
2 green
4 red
8 intensity

Combine the values to get what you want. For the default light-grey on black the value is 07 (hexadecimal).

For a modern black on white the value is F0 (hexadecimal).

A pretty light-cyan on blue is 1B (hexadecimal).

Have fun!
Last edited on
Thank you for your help!
Topic archived. No new replies allowed.