Thread: Extracting COLORREF

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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, 04:32 AM
  3. Extracting only file name from file path
    By President in forum C++ Programming
    Replies: 4
    Last Post: 03-01-2004, 10:51 PM
  4. Extracting Rars
    By (TNT) in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2002, 02:53 AM