Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Color.SetFromCOLORREF method

Applies to: desktop apps only

The Color::SetFromCOLORREF method uses a Windows Graphics Device Interface (GDI)COLORREF value to set the ARGB value of this Color object.

Syntax

VOID SetFromCOLORREF(
  [in]  COLORREF rgb
);

Parameters

rgb [in]

Type: COLORREF

GDICOLORREF value that specifies the red, green, and blue components of this Color object's ARGB value. The default value of the alpha component for this Color object is 255.

Return value

This method does not return a value.

Remarks

A 32-bit GDICOLORREF value contains three, 8-bit color components. The most significant 8 bits are zeros and are not used, the next 8 bits contain the blue component, the next 8 bits contain the green component, and the last 8 bits (the least significant) contain the red component. Note that the ordering (starting with the high-order bits) of the components in a COLORREF value is blue, green, red; whereas, the ordering of an ARGB value is alpha, red, green, blue.

Examples

The following example creates a Color object and sets a GDICOLORREF value. The code then sets the Color object to the value of the GDICOLORREF value, creates a pen, and draws a line.


VOID Example_SetFromCOLORREF(HDC hdc)
{
   Graphics graphics(hdc);

   // Create a color object.
   Color gdipColor(255, 0, 0, 255);

   // COLORREF is defined as an unsigned long in Wingdi.h
   unsigned long gdiColorRef = RGB(0, 0, 0);   // Set a GDI COLORREF value.

   // Set the color object to the COLORREF value.
   gdipColor.SetFromCOLORREF(gdiColorRef);

   // Create a Pen object based on the Color object.
   Pen pen((gdipColor), 10);

   // Draw a line.
   graphics.DrawLine(&pen, 0, 0, 200, 100);
}

Requirements

Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Product

GDI+ 1.0

Header

Gdipluscolor.h (include Gdiplus.h)

Library

Gdiplus.lib

DLL

Gdiplus.dll

See also

Color
Color::MakeARGB
Color::ToCOLORREF

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Additions

ADD
Show:
© 2015 Microsoft