6 Replies - 3248 Views - Last Post: 15 March 2012 - 12:47 PM

#1 nirvanarupali   User is offline

  • D.I.C Stomach
  • member icon

Reputation: 14
  • View blog
  • Posts: 1,120
  • Joined: 01-August 07

Set Text Color

Posted 27 November 2007 - 07:25 PM

Description: Copy and paste this function into your codes. You can pass directly the color code onto the function parameter or ask the number from the user.

This is for windows platform only.

Required header <windows.h>This will change the color of the text output to the screen.
/*******************************************************************  

     Use this function to set the color of text output to the screen. 
     This is for windows platform only.
     
     Required header  <windows.h>

COLOR CODES:

1   BLUE
2   GREEN
3   CYAN
4   RED
5   MAGENTA
6   BROWN
7   LIGHTGRAY
8   DARKGRAY
9   LIGHTBLUE
10  LIGHTGREEN
11  LIGHTCYAN
12  LIGHTRED
13  LIGHTMAGENTA
14  YELLOW
15  WHITE

***********************************************************************/

void setcolor(unsigned int color) 
{                                    
    if (color >15 || color <=0)
    {
        cout <<"Error" <<endl;
        
    }
    else
    {    
        HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleTextAttribute(hcon,color);
    }
}   



Is This A Good Question/Topic? 0
  • +

Replies To: Set Text Color

#2 mhw.info86   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-November 07

Re: Set Text Color

Posted 29 November 2007 - 02:50 AM

Thank you "nirvanarupali" for this function.
Was This Post Helpful? 0
  • +
  • -

#3 nirvanarupali   User is offline

  • D.I.C Stomach
  • member icon

Reputation: 14
  • View blog
  • Posts: 1,120
  • Joined: 01-August 07

Re: Set Text Color

Posted 29 November 2007 - 02:34 PM

your welcome.
Was This Post Helpful? 0
  • +
  • -

#4 tarmizi_adam2005   User is offline

  • جوروترا

Reputation: 287
  • View blog
  • Posts: 986
  • Joined: 18-April 09

Re: Set Text Color

Posted 24 April 2009 - 06:19 PM

thx, this made my programs more neat and pretty ! lol !
Was This Post Helpful? 0
  • +
  • -

#5 nirvanarupali   User is offline

  • D.I.C Stomach
  • member icon

Reputation: 14
  • View blog
  • Posts: 1,120
  • Joined: 01-August 07

Re: Set Text Color

Posted 24 April 2009 - 10:43 PM

No problem
Was This Post Helpful? 0
  • +
  • -

#6 akomismo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 26-July 09

Re: Set Text Color

Posted 25 July 2009 - 11:46 PM

/******************************************************************* Use this function to set the color of text output to the screen. This is for windows platform only. Required header COLOR CODES: 1 BLUE 2 GREEN 3 CYAN 4 RED 5 MAGENTA 6 BROWN 7 LIGHTGRAY 8 DARKGRAY 9 LIGHTBLUE 10 LIGHTGREEN 11 LIGHTCYAN 12 LIGHTRED 13 LIGHTMAGENTA 14 YELLOW 15 WHITE ***********************************************************************/ void setcolor(unsigned int color) { if (color >15 || color <=0) { cout <<"Error" <
Was This Post Helpful? 0
  • +
  • -

#7 techkid52   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 15-March 12

Re: Set Text Color

Posted 15 March 2012 - 12:47 PM

i am having a problem with this code because it wont run. it is saying that there is something wrong with line 28 the void comment
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1