SystemInfo.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Windows.Interop;
  2. namespace Hardcodet.Wpf.TaskbarNotification.Interop
  3. {
  4. /// <summary>
  5. /// This class is a helper for system information, currently to get the DPI factors
  6. /// </summary>
  7. public static class SystemInfo
  8. {
  9. private static readonly System.Windows.Point DpiFactors;
  10. static SystemInfo()
  11. {
  12. using (var source = new HwndSource(new HwndSourceParameters()))
  13. {
  14. if (source.CompositionTarget?.TransformToDevice != null)
  15. {
  16. DpiFactors = new System.Windows.Point(source.CompositionTarget.TransformToDevice.M11, source.CompositionTarget.TransformToDevice.M22);
  17. return;
  18. }
  19. DpiFactors = new System.Windows.Point(1, 1);
  20. }
  21. }
  22. /// <summary>
  23. /// Returns the DPI X Factor
  24. /// </summary>
  25. public static double DpiFactorX => DpiFactors.X;
  26. /// <summary>
  27. /// Returns the DPI Y Factor
  28. /// </summary>
  29. public static double DpiFactorY => DpiFactors.Y;
  30. }
  31. }