Click here to Skip to main content
15,889,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Can someone pls tell me how do I convert COLORREF to char?

I have seen examples to convert them into CString.

COLORREF Color;
char Temp[256];
Color = GetPixel(MemDC,Point2.x,Point2.y);


How do I get Color to Temp as a hex value?

Thanks in Advance

Yes It is.

I am trying to achive the following statement from different pixels.

VB
if (Color1 == "414141" && Color2 == "3a3a3a"
        && Color3 == "d2d2d2" && Color4 == "0"
        && Color5 == "0" )


How else but to either turn the COLORREF into a string or char will I manage to achive that.

I am new at this and trying to degug a code, that was left behind with no comments.
Posted
Updated 5-Aug-10 16:10pm
v2

COLORREF is a plain long which is typedef'ed. Use sprintf with 'x' for format specifier.
 
Share this answer
 
I think you mean this:

C++
COLORREF Color;
char Temp[256];
Color = GetPixel(MemDC,Point2.x,Point2.y);
sprintf_s(Temp, "%06x", Color);
 
Share this answer
 
COLORREF is, as people have said, a typedef of a 32-bit unsigned integer.

So instead of comparing strings, as your example, you can compare values like this:

if (Color1 == 0x414141 && Color2 == 0x3a3a3a
        && Color3 == 0xd2d2d2 && Color4 == 0
        && Color5 == 0 )


This compares Colour1, Color2 and Color3 to three different grey shades (any colour where the three values - Red, Green, Blue - are the same give a greyscale result).
 
Share this answer
 
Comments
SenAPI 7-Aug-10 6:37am    
Reason for my vote of 5
good
SenAPI 7-Aug-10 6:39am    
Reason for my vote of 5
this is the efective solution
How do I get Color to Temp as a hex value?

Isn't COLORREF represented as hex? See here[^]
 
Share this answer
 
Comments
[no name] 6-Aug-10 6:00am    
What do you mean by "represented as hex"? Every thing thats fed to a computer is ultimately a number that can be interpreted as hex if one likes.
Yusuf 6-Aug-10 9:25am    
When specifying an explicit RGB color, the COLORREF value has the following hexadecimal form. 0x00bbggrr
[no name] 6-Aug-10 13:15pm    
That's just a convinient form that's all. You can give that in any form that's considered number by the compiler. Just because you input anything in some form doesn't mean that it is "represented" in that form.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900