How do i work with colors? I read on the MSDN that you can have a RGB macro or COLORREF, but it does not work. Can anyone please give me an example of how to make them work? Thanks :)
Printable View
How do i work with colors? I read on the MSDN that you can have a RGB macro or COLORREF, but it does not work. Can anyone please give me an example of how to make them work? Thanks :)
COLOREF is a type of variable. It holds a color.
Then if you want to get the red green and blue values out of ColorRef, use GetRValue, GetGValue, GetBValue.Code:COLORREF ColorRef;
ColorRef = RGB(RedValue, GreenValue, BlueValue);
Does that answer your question? If not, let me know.
As a matter of course, whenever you encounter a new type, always look it up in the header files for the exact definition. COLORREF is actually an unsigned long (surprised?) and if you look at RGB you can just see how it's packing the 3 bytes into a 4-byte long :)
I don't have any practical information, but it's a useful tidbit :)
Thanks for the tip Pars', but thinking about it, I am not so sure about how the x-bit work. How the memory is allocated differently for them... Could you(or someone else) explain to me ? Thanks a lot :)
Ok. RGB is a macro, so it's expanded at preprocess time (during compilation). If you look at it it's just doing shifting and OR-ing on the individual bytes, so that the 3 bytes you want are stored within the 4-byte long value, and can be moved around as one, with no worries :)