forked from CHMP-HLab/HLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhysicalMonitorEnumerationApi.cs
More file actions
41 lines (29 loc) · 1.52 KB
/
Copy pathPhysicalMonitorEnumerationApi.cs
File metadata and controls
41 lines (29 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Runtime.InteropServices;
namespace HLab.Sys.Windows.API.MonitorConfiguration;
public static partial class PhysicalMonitorEnumerationApi
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct PhysicalMonitor
{
public nint hPhysicalMonitor;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szPhysicalMonitorDescription;
}
[DllImport("dxva2.dll", EntryPoint = "DestroyPhysicalMonitors")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DestroyPhysicalMonitors(
uint dwPhysicalMonitorArraySize, ref PhysicalMonitor[] pPhysicalMonitorArray);
[DllImport("Dxva2.dll", CharSet = CharSet.Auto)]
static extern bool GetNumberOfPhysicalMonitorsFromHMONITOR(nint hMonitor, ref uint pdwNumberOfPhysicalMonitors);
[DllImport("Dxva2.dll", CharSet = CharSet.Auto)]
static extern bool GetPhysicalMonitorsFromHMONITOR(nint hMonitor, uint dwPhysicalMonitorArraySize,
[Out] PhysicalMonitor[] pPhysicalMonitorArray);
public static PhysicalMonitor[] GetPhysicalMonitorsFromHMONITOR(nint hMonitor)
{
uint pdwNumberOfPhysicalMonitors = 0;
if (!GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, ref pdwNumberOfPhysicalMonitors)) return [];
var pPhysicalMonitorArray = new PhysicalMonitor[pdwNumberOfPhysicalMonitors];
if (!GetPhysicalMonitorsFromHMONITOR(hMonitor, pdwNumberOfPhysicalMonitors, pPhysicalMonitorArray)) return [];
return pPhysicalMonitorArray;
}
}