function RGB() - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

function RGB()

EdwardEdward Gent BelgiumPosts: 1Member
edited December 2013 in Beginner C/C++

Hello, i want to program text that comes on the screen in any desired color defined by a function, with given red, green and blue color values. I made a "Hello world" console application.
Question: how can I make that function to steer the color of text. C language seemed to have had a function RGB(r,g,b) but it is strange to my MSC++ 6.0 compiler.
I made some code but it doesn't work properly.

The code below gives errors:

--------------------Configuration: amber text - Win32 Debug--------------------
Compiling...
amber text.cpp
E:\msvc\MSDev98\MyProjects\amber text\amber text.cpp(377) : error C2512: 'Color' : no appropriate default constructor available
E:\msvc\MSDev98\MyProjects\amber text\amber text.cpp(390) : fatal error C1070: mismatched #if/#endif pair in file 'E:\msvc\MSDev98\MyProjects\amber text\amber text.cpp'
Error executing cl.exe.

amber text.exe - 2 error(s), 0 warning(s)

It doesn't recognize the class Color.

// amber text.cpp : Defines the entry point for the console application.
//

include "stdafx.h"

include "stdio.h"

include "windows.h"

include "iostream.h"

include "wingdi.h"

include

include

include <windows.h>

//#define RGB(r,g,b) ( ((DWORD)(BYTE)r)|((DWORD)((BYTE)g)<<8)|((DWORD)((BYTE)b)<<16) )

//#include "Color.h"

ifndef COLOR_H_

define COLOR_H_

//#include
//#include
//#include <windows.h>

class Color {
public:
Color(unsigned char red, unsigned char green, unsigned char blue);
Color(COLORREF);
Color(const std::string&);
private:
friend class DC;
COLORREF color_;
};

Color::Color(unsigned char red, unsigned char green, unsigned char blue) :
color_ (RGB(red, green, blue)) {
}

Color::Color(COLORREF cr) : color_(cr) {

}

Color::Color(const std::string& colorName) {
// if (colorName == "Amber") {
// color_=RGB( 0xFF, 0xBF, 0x00);
// }

if (colorName == "Dark Yellow") {
color_=RGB( 0x99, 0xCC, 0x32);
}
}

int main(){
int Counter = 0;
Color Kleur;

// Kleur.Color(Amber);
while (Counter++ <= 254){

// SetTextColor(255,191,0);
//SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), Counter);
//textcolor(15);
//rgb(255,191,0);
printf("Hello World!\n");
}
return 0;
}

Sign In or Register to comment.