-
text colour
Hello again,
I was recently going thru some source code to try and pinpoint how to change the text colour in dos, anyways so this is what i found...
Code:
#include <stdio.h>
#include <windows.h> // <---*THIS IS THE REQUIRED HEADER FILE FOR IT TOO WORK
int main()
{
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
WORD wOldColorAttrs;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo(h, &csbiInfo);
wOldColorAttrs = csbiInfo.wAttributes;
SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY ); //Set the new color information
printf("TEXT"); //*THESE LINES PRINT THE TEXT
-Curtosy Author of 'Adventures Of You'
Iv'e got a fair idea of whas going on here, but if someone could explain to me the hows and why's of this code that would be awsome.
-
Code:
#include <windows.h>
main() {
system("color fc");
return 0;
}
This one will change the background to white and letters to red.
Type on the prompt "color help" and it will show various color choices there. Then I add whatever color I wanna change to when I write on the code, "system(color /*whatever color*/"); then it changes when you run the program.
-
Unfortunately that wasn't the question, Utopus.
A good place to start when you work with Windows code is usually MSDN. The relevant things here are
As for what part of the structure you changed in your code, there is a WORD in CONSOLE_SCREEN_BUFFER_INFO structures that you can shift around to a specific color, but you are limited to about eight.
Word to the wise: always maintain new and old attributes, because this makes it easy to switch colors back and forth, and you should at least return the console's settings back to the defaults when you are finished messing with color. Also, poorly commented code should be for the most part avoided. Don't comment poorly yourself, and seek out explained examples or documentation when you are learning or looking up something.
-
>Unfortunately that wasn't the question, Utopus.
Sorry, I'm a noobie. :p
-
thanks guys i'll run through those docs now and i'll see what i can get out of em'
-
-
Adrianxw has also some nice tutorials