Results 1 to 8 of 8

Thread: Get the RGB code

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Québec, Canada
    Posts
    131

    Get the RGB code

    Hello,
    How could I get the equivalent in RGB of the COLORREF 4276545?
    Khavoerm Irithyl

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    As far as I remember, a COLORREF is just like an RGB value but ordered the other way.

    So, assuming that in a 4-byte (32-bit) integer they are packed like this:

    RGB packed as - RGBx
    COLORREF packed as - BGRx

    Then all you have to do is switch the red and blue components.

    Code:
    RGB rgbval = 0;
    COLORREF colorref = 4276545;
    
    rgbval = ((colorref & 0xFF) >> 16) & (colorref & 0xFF00) & ((colorref & 0xFF0000) << 16) & (colorref & 0xFF000000);
    If I remembered the format right (no guarantees), that should convert the COLORREF to an RGB.
    Harry.

    "From one thing, know ten thousand things."

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Use GetGValue, GetRValue and GetBValue on COLORREF values to extract the colors.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Location
    Québec, Canada
    Posts
    131
    Thank you for the help.
    Khavoerm Irithyl

  5. #5
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by CornedBee
    Use GetGValue, GetRValue and GetBValue on COLORREF values to extract the colors.
    Just curious, aren't these vb specific functions, because I don't see them in the API viewer?
    Baaaaaaaaah

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    they need to be VB functions because in C they are macros (so you can't get them via declare)

    But since I've never programmed in VB you can be sure that everything I say is either completly wrong or it works for C
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Er, how did you end up at a VB site then?
    Harry.

    "From one thing, know ten thousand things."

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Like many others here - searching for a way to use C dlls in VB (I coded the dll and felt responsible for making it available to the VB programmer I worked with)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width