Hey, I just have a little question...I was woundering if there is a way to make consoleprograms with blue(or any other colors) letters/characters insted of white..do I have to do something with ANSI or ?
btw: Im coding in MS VC++6.0 std.edition
Thx
Hey, I just have a little question...I was woundering if there is a way to make consoleprograms with blue(or any other colors) letters/characters insted of white..do I have to do something with ANSI or ?
btw: Im coding in MS VC++6.0 std.edition
Thx
Here's a code snippet I took from MSDN and modified to get you going. If you want more info look in wincon.h it declares all the structures, attributes and APIs.
Code:#include "stdafx.h" #include <windows.h> #include <iostream> using namespace std; HANDLE hStdout, hStdin; CONSOLE_SCREEN_BUFFER_INFO csbiInfo; int main() { // Get handle to STDIN. hStdout = GetStdHandle(STD_OUTPUT_HANDLE); if ( hStdout == INVALID_HANDLE_VALUE ) { cout << "GetStdHandle" << endl; return 1; } // Save the current text colors. if ( ! GetConsoleScreenBufferInfo( hStdout, &csbiInfo) ) cout << "GetConsoleScreenBufferInfo" << endl; // Set the text attr. to draw red text on black background. if ( ! SetConsoleTextAttribute( hStdout, FOREGROUND_GREEN | BACKGROUND_RED ) ) cout << "SetConsoleTextAttribute" << endl; cout << "this should show new attribute " << endl; cout << "press any key to reset console" << endl; cin.get( ); if ( ! SetConsoleTextAttribute( hStdout, csbiInfo.wAttributes ) ) cout << "Reseting SetConsoleTextAttribute" << endl; cout << "this should show old attributes " << endl; return 0; }
Last edited by Dang; 09-21-2001 at 11:14 PM.
This is easier than the previous...
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE),FOREGROUND_BLUE);
Or for a brighter blue...
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE),FOREGROUND_BLUE | FOREGROUND_INTENSITY);
Just add this line as the very first line in your main() function.
<^>( * ; * )<^>
While it is easier it incurs the overhead of executing the GetStdHandle function, and with all function calls (except inline) that incurs the overhead of the prologue and epilogue every time you change a console color. In this case that probably wouldn't add up to much, but I think it’s important to think about what's going on under the hood and attempt to work at efficiency.
It also lacks error checking.
Yeah, i think i got it new =) Thx guys =)
I was sitting and trying to use the ANSI.SYS file, it worked fine..but I had to make a .bat file to use it, and start it everytime im in DOS =(
thx again
typos..
*now