Files
ShrlAlgoToolkit/WPFluent/Hardware/DpiHelper.cs

33 lines
747 B
C#
Raw Normal View History


using WPFluent.Interop;
using WPFluent.Win32;
namespace WPFluent.Hardware;
/// <summary>
/// Provides access to various DPI-related methods.
/// </summary>
internal static class DpiHelper
{
/// <summary>
/// Default DPI value.
/// </summary>
internal const int DefaultDpi = 96;
public static float ScaleX => GetScale().X;
public static float ScaleY => GetScale().Y;
private static (float X, float Y) GetScale()
{
nint hdc = User32.GetDC(0);
float scaleX = Gdi32.GetDeviceCaps(hdc, Gdi32.DeviceCap.LOGPIXELSX);
float scaleY = Gdi32.GetDeviceCaps(hdc, Gdi32.DeviceCap.LOGPIXELSY);
2025-04-24 20:56:44 +08:00
User32.ReleaseDC(IntPtr.Zero, hdc);
return new(scaleX / 96f, scaleY / 96f);
}
}