SelectPaletteScope
struct SelectPaletteScope
Helper to scope palette selection.
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Windows.Win32.Graphics.Gdi
{
[CompilerFeatureRequired("RefStructs")]
internal readonly ref struct SelectPaletteScope
{
public HDC HDC { get; }
public HPALETTE HPALETTE { get; }
public SelectPaletteScope(HDC hdc, HPALETTE hpalette, bool forceBackground, bool realizePalette)
{
HDC = hdc;
HPALETTE = PInvokeCore.SelectPalette(hdc, hpalette, forceBackground);
if (!HPALETTE.IsNull & realizePalette)
PInvokeCore.RealizePalette(hdc);
}
public static implicit operator HPALETTE([In] [IsReadOnly] ref SelectPaletteScope paletteScope)
{
return paletteScope.HPALETTE;
}
public void Dispose()
{
if (!HPALETTE.IsNull)
PInvokeCore.SelectPalette(HDC, HPALETTE, false);
}
}
}