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