Share via


Color::ToCOLORREF-Methode (gdipluscolor.h)

Die Color::ToCOLORREF-Methode konvertiert den ARGB-Wert dieses Color-Objekts in einen Windows Graphics Device Interface (GDI)COLORREF-Wert.

Syntax

COLORREF ToCOLORREF();

Rückgabewert

Typ: COLORREF

Diese Methode gibt einen GDI COLORREF-Wert zurück, der über die gleichen roten, grünen und blauen Komponenten wie der ARGB-Wert dieser Farbe verfügt.

Hinweise

Wenn der ARGB-Wert in einen COLORREF-Wert konvertiert wird, wird die Alphakomponente des ARGB-Werts ignoriert.

Beispiele

Im folgenden Beispiel werden zwei Color-Objekte erstellt und der ARGB-Wert des ersten Color-Objekts in einen GDI COLORREF-Wert konvertiert. Der Code übergibt dann diesen COLORREF-Wert an die Color::SetFromCOLORREF-Methode des zweiten Color-Objekts . Schließlich verwendet der Code das zweite Color-Objekt , um ein Rechteck zu füllen.

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));
}

Anforderungen

   
Unterstützte Mindestversion (Client) Windows XP, Windows 2000 Professional [nur Desktop-Apps]
Unterstützte Mindestversion (Server) Windows 2000 Server [nur Desktop-Apps]
Zielplattform Windows
Kopfzeile gdipluscolor.h (include Gdiplus.h)
Bibliothek Gdiplus.lib
DLL Gdiplus.dll

Weitere Informationen

Farbe

Color::SetFromCOLORREF