Export (0) Print
Expand All

Color.ToCOLORREF method

Applies to: desktop apps only

The Color::ToCOLORREF method converts this Color object's ARGB value to a Windows Graphics Device Interface (GDI)COLORREF value.

Syntax

COLORREF ToCOLORREF();

Parameters

This method has no parameters.

Return value

Type:

Type: COLORREF

This method returns a GDICOLORREF value that has the same red, green, and blue components as this color's ARGB value.

Remarks

When the ARGB value is converted to a COLORREF value, the alpha component of the ARGB value is ignored.

Examples

The following example creates two Color objects and converts the ARGB value of the first Color object into a GDICOLORREF value. The code then passes that COLORREF value to the Color::SetFromCOLORREF method of the second Color object. Finally, the code uses the second Color object to fill a rectangle.


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

   // Create two Color objects.
   Color firstColor(255, 128, 128, 255);
   Color secondColor(255, 255, 255, 255);

   // Convert the ARGB value of the first color to a COLORREF value.
   COLORREF colorRef = firstColor.ToCOLORREF();

   // Use the COLORREF value to set the color of secondColor.
   secondColor.SetFromCOLORREF(colorRef);

   // Create a SolidBrush object based on secondColor, and fill a rectangle.
   SolidBrush colorRefBrush(secondColor);
   graphics.FillRectangle(&colorRefBrush, Rect(0, 0, 100, 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::SetFromCOLORREF

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Additions

ADD
Show:
© 2014 Microsoft