consoleHANDLE

1
2
3
4
5
6
7
8
HANDLE consoleHANDLE = GetStdHandle( STD_OUTPUT_HANDLE );

		

	cout<<"\311\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\273"
		<<"\n\272"<<SetConsoleTextAttribute( consoleHANDLE, 20)<<"Hit ENTER to continue\272"
		<<"\n\310\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\274";
		cin.ignore();



hey guys, why is there a 1 coming out in the output right before the HIT ENTER??

its confusing the crap out of me. it seems to be coming from the handle color code.
Because SetConsoleTextAttribute( consoleHANDLE, 20) function gets called - and returns
a value of true or false - and it is this return value that is displayed ( 1 for true or 0 for false)
so.. dont put it in between one cout is what you mean?
Yeah, that's what he meant.

1
2
3
4
5
6
7
8
9
cout<<"\311\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\273"
       <<"\n\272";

SetConsoleTextAttribute( consoleHANDLE, 20);

cout <<"Hit ENTER to continue\272"
<<"\n\310\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\315\274";

cin.ignore();


that will work.
Last edited on
Okay thank you. I have never received a good explanation about what return is so i just told myself to ignore it untill I get to higher levels.
While I'm here, anyone can explain to me how I can figure out what my color will turn out without trial and error?
http://cplusplus.com/doc/tutorial/functions/
That will explain functions very well.

Functions have a type, just like '250' could be an int.

so if i had a function that looked like this
1
2
3
4
5
6
7
8
9
10
int Return500()
{
        return 500;
}

//then in main i did this
int main()
{
        cout << Return500() << endl; //the console will output '500', because the function is.. sort of a value itself.
}


The same applies to any other type of data
1
2
3
4
5
6
7
8
9
std::string ReturnHello()
{
        std::string str = "Hello";
        return str; //returns str, which equals "Hello"
}

//......

cout << ReturnHello() << endl; //would output "Hello" 




EDIT: And sure, i'll explain

1
2
3
4
BOOL WINAPI SetConsoleTextAttribute(
  __in  HANDLE hConsoleOutput,
  __in  WORD wAttributes
);


The first parameter is the handle to the console

WORD wAttributes is the color. Different color attributes you can use are here: http://msdn.microsoft.com/en-us/library/ms682088%28v=VS.85%29.aspx#_win32_character_attributes

Example: to set the background to blue and the foreground to red, you'd use
SetConsoleTextAttribute(consoleHANDLE, BACKGROUND_BLUE | FOREGROUND_RED);
Last edited on
Topic archived. No new replies allowed.