|
-
Jan 17th, 2001, 04:17 PM
#1
Thread Starter
Addicted Member
How do I change the fore and/or backcolor of the text that is printed using the printf() function?
-
Jan 17th, 2001, 05:36 PM
#2
Frenzied Member
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
-
Jan 17th, 2001, 05:51 PM
#3
Frenzied Member
'HANDLE' undelcared identifier
-
Jan 17th, 2001, 06:08 PM
#4
Frenzied Member
Code:
#include <windows.h>
....
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle,BACKGROUND_RED);
-
Jan 17th, 2001, 06:43 PM
#5
I just wanna say thats not dos, its a windows console.
-
Jan 17th, 2001, 07:29 PM
#6
Frenzied Member
error C2501: 'SetConsoleTextAttribute' : missing storage-class or type specifiers
-
Jan 17th, 2001, 07:40 PM
#7
Frenzied Member

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;
}
-
Jan 17th, 2001, 08:17 PM
#8
Frenzied Member
Never mind...got it
-
Jan 18th, 2001, 08:39 AM
#9
Thread Starter
Addicted Member
Does this work in dos?
Does that code works in dos mode? I mean when you run the program from DOS, not from a DOS prompt in windows...
-
Jan 18th, 2001, 11:09 AM
#10
Frenzied Member
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.
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jan 18th, 2001, 02:50 PM
#11
Thread Starter
Addicted Member
but in dos then?
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?
-
Jan 18th, 2001, 06:23 PM
#12
Frenzied Member
I think that you will run into the problem that ChimpFace9000 is having. see:
http://forums.vb-world.net/showthrea...threadid=48599
sorry
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|