Files
Shrlalgo.RvKits/WPFluent/Hardware/DpiHelper.cs
2025-05-05 17:04:06 +08:00

33 lines
747 B
C#

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);
User32.ReleaseDC(IntPtr.Zero, hdc);
return new(scaleX / 96f, scaleY / 96f);
}
}