diff --git a/PInvoke/Gdi32/WinGdi.cs b/PInvoke/Gdi32/WinGdi.cs index bb0d5add..b5512447 100644 --- a/PInvoke/Gdi32/WinGdi.cs +++ b/PInvoke/Gdi32/WinGdi.cs @@ -432,5 +432,70 @@ namespace Vanara.PInvoke [return: MarshalAs(UnmanagedType.Bool)] [PInvokeData("Wingdi.h", MSDNShortId = "dd145141")] public static extern bool TransparentBlt(SafeDCHandle hdcDest, int xOriginDest, int yOriginDest, int wDest, int hDest, SafeDCHandle hdcSrc, int xOriginSrc, int yOriginSrc, int wSrc, int hSrc, int crTransparent); + + /// The COLORREF value is used to specify an RGB color in the form 0x00bbggrr. + [PInvokeData("WinDef.h")] + [StructLayout(LayoutKind.Explicit, Size = 4)] + public struct COLORREF + { + /// The DWORD value + [FieldOffset(0)] + private uint Value; + /// The intensity of the red color. + [FieldOffset(0)] + public byte R; + /// The intensity of the green color. + [FieldOffset(1)] + public byte G; + /// The intensity of the blue color. + [FieldOffset(2)] + public byte B; + + /// Initializes a new instance of the struct. + /// The intensity of the red color. + /// The intensity of the green color. + /// The intensity of the blue color. + public COLORREF(byte r, byte g, byte b) + { + Value = 0; + R = r; + G = g; + B = b; + } + + /// Initializes a new instance of the struct. + /// The packed DWORD value. + public COLORREF(uint value) + { + R = 0; + G = 0; + B = 0; + Value = value & 0x00FFFFFF; + } + + /// Initializes a new instance of the struct. + /// The color. + public COLORREF(System.Drawing.Color color) : this(color.R, color.G, color.B) { } + + /// Performs an implicit conversion from to . + /// The value. + /// The result of the conversion. + public static implicit operator System.Drawing.Color(COLORREF cr) => System.Drawing.Color.FromArgb(cr.R, cr.G, cr.B); + + /// Performs an implicit conversion from to . + /// The value. + /// The result of the conversion. + public static implicit operator COLORREF(System.Drawing.Color clr) => new COLORREF(clr); + + /// Performs an implicit conversion from to . + /// The value. + /// The result of the conversion. + public static implicit operator uint(COLORREF cr) => cr.Value; + + /// Performs an implicit conversion from to . + /// The value. + /// The result of the conversion. + public static implicit operator COLORREF(uint value) => new COLORREF(value); + } } } \ No newline at end of file