wabbajack/Wabbajack/Util/SystemParametersConstructor.cs

55 lines
1.9 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using MahApps.Metro.Controls;
using Microsoft.VisualBasic;
using PInvoke;
2020-01-07 13:50:11 +00:00
using Wabbajack.Lib;
using static PInvoke.User32;
using static PInvoke.Gdi32;
2020-01-07 13:50:11 +00:00
namespace Wabbajack.Util
{
// Much of the GDI code here is taken from : https://github.com/ModOrganizer2/modorganizer/blob/master/src/envmetrics.cpp
// Thanks to MO2 for being good citizens and supporting OSS code
2020-01-07 13:50:11 +00:00
public static class SystemParametersConstructor
{
private static List<(int Width, int Height, bool IsPrimary)> GetDisplays()
{
// Needed to make sure we get the right values from this call
SetProcessDPIAware();
unsafe
{
var col = new List<(int Width, int Height, bool IsPrimary)>();
EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero,
delegate(IntPtr hMonitor, IntPtr hdcMonitor, RECT* lprcMonitor, void *dwData)
{
MONITORINFOEX mi = new MONITORINFOEX();
mi.cbSize = Marshal.SizeOf(mi);
bool success = GetMonitorInfo(hMonitor, (MONITORINFO*)&mi);
if (success)
{
col.Add(((mi.Monitor.right - mi.Monitor.left), (mi.Monitor.bottom - mi.Monitor.top), mi.Flags == 1));
}
return true;
}, IntPtr.Zero);
return col;
}
}
2020-01-07 13:50:11 +00:00
public static SystemParameters Create()
{
var (width, height, _) = GetDisplays().First(d => d.IsPrimary);
2020-01-07 13:50:11 +00:00
return new SystemParameters
{
ScreenWidth = width,
ScreenHeight = height
2020-01-07 13:50:11 +00:00
};
}
}
}