Extracting COLORREF

This is a discussion on Extracting COLORREF within the Windows Programming forums, part of the Platform Specific Boards category; How can I convert a COLORREF varible to three integers (int r, g, b ? I have been stumped about ...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Question Extracting COLORREF

    How can I convert a COLORREF varible to three integers (int r, g, b? I have been stumped about this for a very long time, thanks for any help, Queatrix.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,474
    When specifying an explicit RGB color, the COLORREF value has the following hexadecimal form:

    0x00bbggrr
    So just bitshifting and masking would be enough

    g = (cr >> 8) & 0xFF;

    or as suggested in the MSDN
    To create a COLORREF color value, use the RGB macro. To extract the individual values for the red, green, and blue components of a color value, use the GetRValue, GetGValue, and GetBValue macros, respectively.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Thanks, thats what I needed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. colorref and setpixel
    By bballzone in forum C++ Programming
    Replies: 19
    Last Post: 09-11-2004, 06:09 PM
  2. Making COLORREF lighter
    By Mithoric in forum Windows Programming
    Replies: 1
    Last Post: 03-02-2004, 03:32 AM
  3. Extracting only file name from file path
    By President in forum C++ Programming
    Replies: 4
    Last Post: 03-01-2004, 09:51 PM
  4. Extracting Rars
    By (TNT) in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2002, 02:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21