How do I change the fore and/or backcolor of the text that is printed using the printf() function?
Printable View
How do I change the fore and/or backcolor of the text that is printed using the printf() function?
Code:HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle,BACKGROUND_RED);
Code://extra info
Specifies the foreground and background color attributes. Any combination of the following values can be specified: FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_RED, FOREGROUND_INTENSITY, BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_RED, and BACKGROUND_INTENSITY. For example, the following combination of values produces white text on a black background:
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
'HANDLE' undelcared identifier :(
Code:#include <windows.h>
....
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle,BACKGROUND_RED);
I just wanna say thats not dos, its a windows console.
error C2501: 'SetConsoleTextAttribute' : missing storage-class or type specifiers :(
:rolleyes:
Code:#include<iostream.h>
#include <windows.h>
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle,BACKGROUND_BLUE);
SetConsoleTextAttribute(handle,FOREGROUND_RED && FOREGROUND_BLUE && FOREGROUND_GREEN && FOREGROUND_INTENSITY);
int main()
{
int dummy;
int newString[101]
cout<<"Hello"<<endl;
cin.getline(newString,101,'\n')
cin>>dummy;
return 0;
}
Never mind...got it :rolleyes:
Does that code works in dos mode? I mean when you run the program from DOS, not from a DOS prompt in windows...
No it would not because you are using the window.h, a windows only library, to set the DOS console colors, not the DOS colors. So you would have to be in windows for this to work.
But I want to know how to do it in DOS! It have to work in a way or another...
It's done in almost every game written for DOS. Take Doom as an example... When you start doom.exe the program initializes everything (the WAD etc) etc... The first room is white colored text with red background that says "DOOM V1.1666" or whatever... How do I do that?
I think that you will run into the problem that ChimpFace9000 is having. see:
http://forums.vb-world.net/showthrea...threadid=48599
sorry