<PackageReference Include="System.Drawing.Common" Version="10.0.2" />

Windows.Win32.Graphics.Gdi.DeviceContextHdcScope

Helper to scope getting a HDC from a IHdcContext object. Releases the HDC when disposed, unlocking the parent IHdcContext object.

Also saves and restores the state of the HDC.

namespace Windows.Win32.Graphics.Gdi { internal readonly ref struct DeviceContextHdcScope { public IHdcContext DeviceContext { get; } public HDC HDC { get; } public DeviceContextHdcScope(IHdcContext deviceContext, bool applyGraphicsState = true, bool saveHdcState = false); public DeviceContextHdcScope(IHdcContext deviceContext, ApplyGraphicsProperties applyGraphicsState, bool saveHdcState = false); public static implicit operator HDC(ref DeviceContextHdcScope scope); public static implicit operator IntPtr(ref DeviceContextHdcScope scope); public static explicit operator WPARAM(ref DeviceContextHdcScope scope); public void Dispose(); } }