Change Console background to a colour

I want to be able to change the entire default console background to the colour green. Many people have posted examples but when I use:

1
2
3
4
 int main()
{
	SetConsoleTextAttribute(
		GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_GREEN);


This only changes the text background to green not the actual console background, how can I do this?
Last edited on
Calling ClrScr() after setting the bg color should do.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void ClrScr()
{
  COORD coordScreen = { 0, 0 };  
  DWORD cCharsWritten;
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  DWORD dwConSize;
  HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

  GetConsoleScreenBufferInfo(hConsole, &csbi);
  dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
  FillConsoleOutputCharacter(hConsole, ' ', dwConSize, coordScreen,
    &cCharsWritten);

  GetConsoleScreenBufferInfo(hConsole, &csbi);
  FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize,
    coordScreen, &cCharsWritten);

  SetConsoleCursorPosition(hConsole, coordScreen);
}
@Thomas1965 - no that doesn't seem to work.
Sorted it!
@Robin53 Care to share your solution, so that others can learn from this thread?
I used system("color 20");
Topic archived. No new replies allowed.