Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

colors in XP-console with C

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
5 replies to this topic

#1 SnAkE   Members   

122
Like
0Likes
Like

Posted 07 January 2005 - 10:55 PM

Hi there, I am just writing a few small C programs for my university in C and asked myself if it was possible to color the text I am printing to the screen?! I tried the known escape-sequences of printf, but the do not have any effect... So do you know if it ist possible? Thanx, snAKe

#2 SumDude   Members   

163
Like
0Likes
Like

Posted 07 January 2005 - 11:14 PM

http://msdn.microsoft.com/library/en-us/dllproc/base/consoles.asp

You need to make a handle to the console and then use that to change the color

 
void main()
{
HANDLE console;

//Make a new handle to the output handle
console = GetStdHandle(STD_OUTPUT_HANDLE);

//Set the text attributes
SetConsoleTextAttribute(console, FOREGROUND_GREEN);

//output info
cout << "Hey" << endl;
//Free the console handle
FreeConsole();

return 0;
}




#3 Zipster   Members   

2257
Like
0Likes
Like

Posted 07 January 2005 - 11:19 PM

That would work, except for the fact that he said he's using C (so cout wouldn't fly) and we don't know if he can access the Windows API, or if he's even developing these programs under Windows.

As far as I know, the escape sequences only work when ANSI.SYS is loaded. In the old days this was as easy as adding it to config.sys, but nowadays you'd probably have to go spelunking through 'msconfig' to change things. I don't know how to load device drivers under Linux [sad]

The other traditional methods for working with the display in C were using BIOS interrupts and DMA. However you won't get too far calling interrupts, and it's unlikely you'll get direct access to the console buffer memory. So I'd say to stick with the escape sequences and see how they work for you.

EDIT: And it looks like I win the post race [grin]

#4 Oluseyi   Members   

2076
Like
0Likes
Like

Posted 07 January 2005 - 11:19 PM

SetConsoleTextAttribute
Character Attributes

#5 Oluseyi   Members   

2076
Like
0Likes
Like

Posted 07 January 2005 - 11:20 PM

Quote:
Original post by Zipster
...we don't know if he can access the Windows API, or if he's even developing these programs under Windows.
Quote:
Thread title
colors in XP-console with C


#6 Zipster   Members   

2257
Like
0Likes
Like

Posted 07 January 2005 - 11:22 PM

Oh. Well I guess it sometimes pays to pay attention to the original subject line when you reply [smile] But I'm still faster... and the escape sequences are more portible so mweh!

*slinks away*




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.