Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Help with coloring text

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
clanner
Master Cheater
Reputation: 0

Joined: 26 Jul 2006
Posts: 290

PostPosted: Mon Oct 20, 2008 4:53 pm    Post subject: [C++] Help with coloring text Reply with quote

Alright this is my code:
Code:
#include <iostream>
#include <windows.h>
#include <string>
#include <stdlib.h>
using namespace std;

//Voids for colors
void blue()
{
   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
}

void red()
{
   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
}

void green()
{
   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
}

void cyan()
{
   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN);
}

void yellow()
{
   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED);
}

void white()
{
   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
}
//end of voids for colors

int main()
{
   blue();
   cout << "This is blue!" << endl;
   cout << "*****************";
   white();
   cout << "This is white!";
   blue();
   cout << "blue again!" << endl;
   cout << "also blue!" << endl;
   cin.sync();
   cin.ignore();
   return 0;
}


What I want is this, the color part
Code:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN)


Is there a way instead of writing all that to make it be just like this? The reason for asking is because making all those voids make it look "messy".
Code:
blue = GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN


SetConsoleTextAttribute(Blue)


Thank you.

PS (I'm not sure if you will understand what I'm asking.)
Back to top
View user's profile Send private message AIM Address
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Mon Oct 20, 2008 5:01 pm    Post subject: Reply with quote

Code:
private void setTextColor(string color)
{
   Switch(color) {
            case "blue":
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
            break;
            case "red":
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
            break;
            case "green":
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
            break;
            case "cyan":
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN);
            break;
            case "yellow":
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED);
            break;
            case "white":
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN);
            break;

            default:
            color == "white";
            break;
}


To assign a text color, simply write setTextColor("colorhere");

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
GMZorita
Grandmaster Cheater Supreme
Reputation: 0

Joined: 21 Mar 2007
Posts: 1361

PostPosted: Mon Oct 20, 2008 5:04 pm    Post subject: Reply with quote

Code:
#define blue GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE

_________________
Gone
Back to top
View user's profile Send private message
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Mon Oct 20, 2008 5:06 pm    Post subject: Reply with quote

GMZorita wrote:
Code:
#define blue GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE

Ahh.

* I should start with C++ soon.

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
GMZorita
Grandmaster Cheater Supreme
Reputation: 0

Joined: 21 Mar 2007
Posts: 1361

PostPosted: Mon Oct 20, 2008 5:46 pm    Post subject: Reply with quote

If your going to use
Code:

#define blue GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE

SetConsoleTextAttribute(blue);


I suggest you to just use
Code:

#define blue()   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);

Since your going to define to every colour anyway.

_________________
Gone
Back to top
View user's profile Send private message
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Mon Oct 20, 2008 6:06 pm    Post subject: Reply with quote

Code:
void ChangeColor(int Color)
{
   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), Color);
}


white = 15
red = 10 or 12
green = the other one that is not red

That is all I remember off the top of my head.

_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
clanner
Master Cheater
Reputation: 0

Joined: 26 Jul 2006
Posts: 290

PostPosted: Mon Oct 20, 2008 7:32 pm    Post subject: Reply with quote

GMZorita wrote:
If your going to use
Code:

#define blue GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE

SetConsoleTextAttribute(blue);


I suggest you to just use
Code:

#define blue()   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);

Since your going to define to every colour anyway.


Code:

#define blue()   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);


Just curious but do I need to add the () after blue or can I just leave it as
Code:
#define blue
Back to top
View user's profile Send private message AIM Address
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Mon Oct 20, 2008 8:03 pm    Post subject: Reply with quote

clanner wrote:
GMZorita wrote:
If your going to use
Code:

#define blue GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE

SetConsoleTextAttribute(blue);


I suggest you to just use
Code:

#define blue()   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);

Since your going to define to every colour anyway.


Code:

#define blue()   SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);


Just curious but do I need to add the () after blue or can I just leave it as
Code:
#define blue


You need the parentheses, you are defining a function, all functions have the parentheses whether empty or with parameters.
Back to top
View user's profile Send private message
clanner
Master Cheater
Reputation: 0

Joined: 26 Jul 2006
Posts: 290

PostPosted: Mon Oct 20, 2008 8:11 pm    Post subject: Reply with quote

Okay thank you!
Back to top
View user's profile Send private message AIM Address
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Mon Oct 20, 2008 9:11 pm    Post subject: Reply with quote

What? He doesn't need the parenthesis. He is not defining a function, if he were to use parenthesis it would be a macro. He has no need for that since he is not passing a variable to the macro.
_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Tue Oct 21, 2008 1:09 am    Post subject: Reply with quote

Code:
#define WHITE FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN


No need to call GetStdHandle EVERY time.
Back to top
View user's profile Send private message MSN Messenger
clanner
Master Cheater
Reputation: 0

Joined: 26 Jul 2006
Posts: 290

PostPosted: Tue Oct 21, 2008 8:07 am    Post subject: Reply with quote

What exactly does GetStdHandle do? I just copied the code from somewhere and understood "most" of it except for that.
Back to top
View user's profile Send private message AIM Address
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Tue Oct 21, 2008 8:19 am    Post subject: Reply with quote

http://msdn.microsoft.com/en-us/library/ms683231(VS.85).aspx
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites