Color::ToCOLORREF method (gdipluscolor.h)
The Color::ToCOLORREF method converts this Color object's ARGB value to a Windows Graphics Device Interface (GDI)COLORREF value.
Syntax
COLORREF ToCOLORREF();
Return value
Type: COLORREF
This method returns a GDI COLORREF 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 GDI COLORREF 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
Requirement | Value |
---|---|
Minimum supported client | Windows XP, Windows 2000 Professional [desktop apps only] |
Minimum supported server | Windows 2000 Server [desktop apps only] |
Target Platform | Windows |
Header | gdipluscolor.h (include Gdiplus.h) |
Library | Gdiplus.lib |
DLL | Gdiplus.dll |