This commit is contained in:
Daniel Clark
2021-02-05 01:39:51 +00:00
parent 666067a36c
commit 45a9eb9cd2
73 changed files with 2669 additions and 0 deletions
@@ -0,0 +1,47 @@
using Microsoft.Windows.Sdk;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows;
namespace NotificationFlyout.Wpf.UI.Helpers
{
public static class SystemInformationHelper
{
private const int SM_CXSCREEN = 0;
private const int SM_CYSCREEN = 1;
private const int SPI_GETWORKAREA = 48;
public static Rect VirtualScreen => GetVirtualScreen();
public static Rect WorkingArea => GetWorkingArea();
public static int GetCurrentDpi()
{
return (int)typeof(SystemParameters).GetProperty("Dpi", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null, null);
}
public static double GetCurrentDpiScaleFactor()
{
return (double)GetCurrentDpi() / 96;
}
private static Rect GetVirtualScreen()
{
var size = new Size(PInvoke.GetSystemMetrics(SM_CXSCREEN), PInvoke.GetSystemMetrics(SM_CYSCREEN));
return new Rect(0, 0, size.Width, size.Height);
}
private static Rect GetWorkingArea()
{
var rect = new RECT();
SystemParametersInfo(SPI_GETWORKAREA, 0, ref rect, 0);
return new Rect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern bool SystemParametersInfo(int nAction, int nParam, ref RECT rc, int nUpdate);
}
}