Text and background color in C++

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 168273 Views - Last Post: 24 May 2013 - 04:36 PM Rate Topic: ***** 1 Votes

#16 jjhaag  Icon User is offline

  • me editor am smartastic
  • member icon

Reputation: 45
  • View blog
  • Posts: 1,789
  • Joined: 18-September 07

Re: Text and background color in C++

Posted 21 January 2008 - 10:46 PM

Thread split.

Link to new thread on the performance of cin.get() versus system("PAUSE") can be found at http://www.dreaminco...wtopic41434.htm
Was This Post Helpful? 0
  • +
  • -

#17 mark5rockzz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-February 12

Re: Text and background color in C++

Posted 27 March 2012 - 01:48 PM

View PostBitByte, on 20 October 2006 - 08:22 AM, said:

Here's some code that might get you started. Did it a long time ago. I don't know how to set the background though :rolleyes:

// February 2006 using excellent code::blocks IDE with mingw
// C++ Code for changing colors of text in the console window
#include <iostream>
#include <windows.h>

using namespace std;

int main()
{

	HANDLE hConsole;
	hConsole = GetStdHandle (STD_OUTPUT_HANDLE);

// Use the three primary colors for mixing any other color.
// Use FOREGROUND_INTENSITY for brighter colors.
	SetConsoleTextAttribute
	(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY);
			cout << "Bright red text\n";

	SetConsoleTextAttribute
	(hConsole, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
			cout << "Bright blue text\n";

	SetConsoleTextAttribute
	(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
			cout << "Back to normal white text\n";

// Wait for user pressing key before exiting
// Gives them a chance to see the output
			cout << "\n\nPress any key to exit program.....";
			cin.get();

		return 0;
}




how about this

HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
for(int i = 0;i <= 255;i++){
SetConsoleTextAttribute(handle, i);
cout<<"\n #"<<i+1;
}
Was This Post Helpful? 0
  • +
  • -

#18 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5388
  • View blog
  • Posts: 27,384
  • Joined: 10-May 07

Re: Text and background color in C++

Posted 27 March 2012 - 09:52 PM

How about not bumping a six year old thread?

Plus the original poster has not signed onto the forum since 2007. I doubt he's going to come back to check on his color printing topic ;)
Was This Post Helpful? 0
  • +
  • -

#19 ashjack  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-April 12

Re: Text and background color in C++

Posted 21 April 2012 - 04:12 AM

View Postspooky, on 20 October 2006 - 02:59 PM, said:

well can i use other colors exept red or blue?
i tried yello and gray but nothink happent...

does anyone know how to chang back color?


To make yellow, you use green and red. I don't know what makes gray though...
Was This Post Helpful? 0
  • +
  • -

#20 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5388
  • View blog
  • Posts: 27,384
  • Joined: 10-May 07

Re: Text and background color in C++

Posted 21 April 2012 - 08:29 PM

Where were you six years ago?
Was This Post Helpful? 0
  • +
  • -

#21 Delacar  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 31-July 12

Re: Text and background color in C++

Posted 24 May 2013 - 03:10 PM

Hi, I was wondering if there is a way to change the whole background with out using system (color). Also I would like to know use this
void setcolor(unsigned short color)
{
    HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hcon,color);
}




without changing the background color. If any one can tell me that would be great. :)
Was This Post Helpful? 0
  • +
  • -

#22 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,466
  • Joined: 05-May 12

Re: Text and background color in C++

Posted 24 May 2013 - 04:36 PM

Please do not re-open old threads. Open a new topic instead.

This post has been edited by Skydiver: 24 May 2013 - 04:36 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2