Colapsed COLORREF and ImageListDrawColor

pull/10/head
David Hall 2018-06-08 11:22:49 -06:00
parent 50f6efb0ff
commit 685cd231ac
1 changed files with 14 additions and 3 deletions

View File

@ -434,7 +434,9 @@ namespace Vanara.PInvoke
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);
/// <summary>The COLORREF value is used to specify an RGB color in the form <c>0x00bbggrr</c>.</summary>
[PInvokeData("WinDef.h")]
// typedef DWORD COLORREF;typedef DWORD* LPCOLORREF;
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd183449(v=vs.85).aspx
[PInvokeData("Windef.h", MSDNShortId = "dd183449")]
[StructLayout(LayoutKind.Explicit, Size = 4)]
public struct COLORREF
{
@ -451,6 +453,9 @@ namespace Vanara.PInvoke
[FieldOffset(2)]
public byte B;
private const uint CLR_NONE = 0xFFFFFFFF;
private const uint CLR_DEFAULT = 0xFF000000;
/// <summary>Initializes a new instance of the <see cref="COLORREF"/> struct.</summary>
/// <param name="r">The intensity of the red color.</param>
/// <param name="g">The intensity of the green color.</param>
@ -475,12 +480,12 @@ namespace Vanara.PInvoke
/// <summary>Initializes a new instance of the <see cref="COLORREF"/> struct.</summary>
/// <param name="color">The color.</param>
public COLORREF(System.Drawing.Color color) : this(color.R, color.G, color.B) { }
public COLORREF(System.Drawing.Color color) : this(color == System.Drawing.Color.Transparent ? CLR_NONE : (uint)System.Drawing.ColorTranslator.ToWin32(color)) { }
/// <summary>Performs an implicit conversion from <see cref="COLORREF"/> to <see cref="System.Drawing.Color"/>.</summary>
/// <param name="cr">The <see cref="COLORREF"/> value.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator System.Drawing.Color(COLORREF cr) => System.Drawing.Color.FromArgb(cr.R, cr.G, cr.B);
public static implicit operator System.Drawing.Color(COLORREF cr) => cr.Value == CLR_NONE ? System.Drawing.Color.Transparent : System.Drawing.Color.FromArgb(cr.R, cr.G, cr.B);
/// <summary>Performs an implicit conversion from <see cref="System.Drawing.Color"/> to <see cref="COLORREF"/>.</summary>
/// <param name="clr">The <see cref="System.Drawing.Color"/> value.</param>
@ -496,6 +501,12 @@ namespace Vanara.PInvoke
/// <param name="value">The <see cref="uint"/> value.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator COLORREF(uint value) => new COLORREF(value);
/// <summary>Static reference for CLR_NONE representing no color.</summary>
public static COLORREF None = new COLORREF(CLR_NONE);
/// <summary>Static reference for CLR_DEFAULT representing the default color.</summary>
public static COLORREF Default = new COLORREF(0xFF000000);
}
}
}