SaveDcScope
struct SaveDcScope
Helper to scope lifetime of a saved device context state.
using System.Runtime.CompilerServices;
namespace Windows.Win32.Graphics.Gdi
{
[CompilerFeatureRequired("RefStructs")]
internal readonly ref struct SaveDcScope
{
private readonly int _savedState;
public HDC HDC { get; }
public SaveDcScope(HDC hdc)
{
_savedState = PInvokeCore.SaveDC(hdc);
HDC = hdc;
}
public void Dispose()
{
if (_savedState != 0)
PInvokeCore.RestoreDC(HDC, _savedState);
}
}
}