/// <summary> /// Enters given Dpi awareness scope /// </summary> public DpiAwarenessScope(DpiAwarenessContext awareness) { if (EnableDpiChangedHighDpiImprovements) { try { if (!CommonUnsafeNativeMethods.TryFindDpiAwarenessContextsEqual(awareness, DpiAwarenessContext.DPI_AWARENESS_CONTEXT_UNSPECIFIED)) { originalAwareness = CommonUnsafeNativeMethods.GetThreadDpiAwarenessContext(); // If current process dpiawareness is SYSTEM_UNAWARE or SYSTEM_AWARE (must be equal to awareness), calling this method will be a no-op. if (!CommonUnsafeNativeMethods.TryFindDpiAwarenessContextsEqual(originalAwareness, awareness) && !CommonUnsafeNativeMethods.TryFindDpiAwarenessContextsEqual(originalAwareness, DpiAwarenessContext.DPI_AWARENESS_CONTEXT_UNAWARE)) { originalAwareness = CommonUnsafeNativeMethods.SetThreadDpiAwarenessContext(awareness); dpiAwarenessScopeIsSet = true; } } } catch (EntryPointNotFoundException) { dpiAwarenessScopeIsSet = false; } } }