SetMapModeScope
struct SetMapModeScope
Helper to scope selecting a given mapping mode into a HDC. Restores the original mapping mode into the HDC
when disposed.
using System.Runtime.CompilerServices;
namespace Windows.Win32.Graphics.Gdi
{
[CompilerFeatureRequired("RefStructs")]
internal readonly ref struct SetMapModeScope
{
private readonly HDC_MAP_MODE _previousMapMode;
private readonly HDC _hdc;
public SetMapModeScope(HDC hdc, HDC_MAP_MODE mapMode)
{
_previousMapMode = (HDC_MAP_MODE)PInvokeCore.SetMapMode(hdc, mapMode);
_hdc = ((mapMode == _previousMapMode) ? default(HDC) : hdc);
}
public void Dispose()
{
if (!_hdc.IsNull)
PInvokeCore.SetMapMode(_hdc, _previousMapMode);
}
}
}