Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 09-27-2005, 09:27 PM   #1 (permalink)
Manan
Registered User
 
Join Date: Jul 2005
Posts: 16
Manan is on a distinguished road
Cool color/size in console

I am still a bit new to c++, and i was wondering how to change the color in a console application(i mean in code, not by going to properties.)
Manan is offline   Reply With Quote
Old 09-28-2005, 07:00 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Under Unix it's called programming with ncurses
There might be something similar in the windows world.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 09-28-2005, 09:48 AM   #3 (permalink)
TheSheep
Registered User
 
TheSheep's Avatar
 
Join Date: Mar 2005
Location: UK
Posts: 11
TheSheep is on a distinguished road
Send a message via ICQ to TheSheep Send a message via AIM to TheSheep Send a message via MSN to TheSheep Send a message via Yahoo to TheSheep
In a Windows console, use SetConsoleTextAttribute()

In a true DOS terminal, not a Win32 DOS-style console (these usually aren't supported on modern compilers), use textcolor and textbackground.
These aren't especially well-document so here it is:
Quote:
#include <conio.h>
void textcolor(int newcolor);
void textbackground(int newcolor);

newcolor can take one of the following constant values:
BLACK 0
BLUE 1
GREEN 2
CYAN 3
RED 4
MAGENTA 5
BROWN 6
LIGHTGRAY 7
The following are also valid, but may not be supported on some machines and will be displayed as their darker equivalents above:
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11
LIGHTRED 12
LIGHTMAGENTA 13
YELLOW 14
WHITE 15

You can add BLINK to the newcolor for textcolor() to make it blink:
BLINK 128
e.g. textcolor(CYAN+BLINK);

textcolor and textbackground will only affect functions that use direct video output, such as cprintf. printf does not. I strongly doubt that iostream functions use DVO.
In both these cases, just call it before writing the coloured text.
To change the entire screen, a quick and easy way is to call the function/s followed by system("cls");

The final option is directly modifying the display's memory space, but I doubt this is 21st-century compatible, particularly in a multithreaded OS with terminal emulation. Likelihood is that you'll be using the first one.
TheSheep is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
console app full screen HELP! Manan Windows 2 09-25-2005 08:48 PM
HELP console exits once i start program fuzzybunny3 Standard C, C++ 3 10-24-2004 09:10 PM
Phantom Game Console.. is it really all that? sde Lounge 1 08-27-2003 06:38 PM
Linux hackers crack Xbox console redhead Code Newbie News 0 07-05-2003 12:49 AM
c++.net console app ? sde Standard C, C++ 5 03-13-2003 07:07 AM


All times are GMT -8. The time now is 12:20 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting