特定屏幕的可用分辨率
Available Resolutions For a specific Screen
我可能有 2 个 monitor/screens 连接到我的机器。
我想知道特定屏幕的所有可用分辨率(我有一个 System.Windows.Forms.Screen 类型的实例)。
我看过以下内容:
How to list available video modes using C#?
List of valid resolutions for a given Screen?
但它们都给出了所有显示器的结果,而不仅仅是特定的显示器。有什么建议么?谢谢!!!
编辑 1:
这是关于我的 2 个屏幕的信息:
在第一个链接中,您被告知 EnumDisplaySettings
。花几秒钟 lookup that function 并且 第一个参数 是
string that specifies the display device about whose graphics mode the
function will obtain information.
这是一个示例 class,用于获取有关显示器的信息。我故意省略了 DEVMODE
因为你已经知道了。
public class NativeMethods
{
[DllImport("user32.dll")]
public static extern bool EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE devMode);
[DllImport("user32.dll")]
public static extern bool EnumDisplayDevices(string deviceName, int modeNum, ref DISPLAY_DEVICE displayDevice, int flags);
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAY_DEVICE
{
public int cb;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string DeviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string DeviceString;
public int StateFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string DeviceID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string DeviceKey;
}
static class Display
{
public static List<DISPLAY_DEVICE> GetGraphicsAdapters()
{
int i = 0;
DISPLAY_DEVICE displayDevice = new DISPLAY_DEVICE();
List<DISPLAY_DEVICE> result = new List<DISPLAY_DEVICE>();
displayDevice.cb = Marshal.SizeOf(displayDevice);
while (NativeMethods.EnumDisplayDevices(null, i, ref displayDevice, 1))
{
result.Add(displayDevice);
i++;
}
return result;
}
public static List<DISPLAY_DEVICE> GetMonitors(string graphicsAdapter)
{
DISPLAY_DEVICE displayDevice = new DISPLAY_DEVICE();
List<DISPLAY_DEVICE> result = new List<DISPLAY_DEVICE>();
int i = 0;
displayDevice.cb = Marshal.SizeOf(displayDevice);
while (NativeMethods.EnumDisplayDevices(graphicsAdapter, i, ref displayDevice, 0))
{
result.Add(displayDevice);
i++;
}
return result;
}
public static List<DEVMODE> GetDeviceModes(string graphicsAdapter)
{
int i = 0;
DEVMODE devMode = new DEVMODE();
List<DEVMODE> result = new List<DEVMODE>();
while (NativeMethods.EnumDisplaySettings(graphicsAdapter, i, ref devMode))
{
result.Add(devMode);
i++;
}
return result;
}
}
我可能有 2 个 monitor/screens 连接到我的机器。 我想知道特定屏幕的所有可用分辨率(我有一个 System.Windows.Forms.Screen 类型的实例)。
我看过以下内容: How to list available video modes using C#?
List of valid resolutions for a given Screen?
但它们都给出了所有显示器的结果,而不仅仅是特定的显示器。有什么建议么?谢谢!!!
编辑 1:
这是关于我的 2 个屏幕的信息:
在第一个链接中,您被告知 EnumDisplaySettings
。花几秒钟 lookup that function 并且 第一个参数 是
string that specifies the display device about whose graphics mode the function will obtain information.
这是一个示例 class,用于获取有关显示器的信息。我故意省略了 DEVMODE
因为你已经知道了。
public class NativeMethods
{
[DllImport("user32.dll")]
public static extern bool EnumDisplaySettings(string deviceName, int modeNum, ref DEVMODE devMode);
[DllImport("user32.dll")]
public static extern bool EnumDisplayDevices(string deviceName, int modeNum, ref DISPLAY_DEVICE displayDevice, int flags);
}
[StructLayout(LayoutKind.Sequential)]
public struct DISPLAY_DEVICE
{
public int cb;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string DeviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string DeviceString;
public int StateFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string DeviceID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string DeviceKey;
}
static class Display
{
public static List<DISPLAY_DEVICE> GetGraphicsAdapters()
{
int i = 0;
DISPLAY_DEVICE displayDevice = new DISPLAY_DEVICE();
List<DISPLAY_DEVICE> result = new List<DISPLAY_DEVICE>();
displayDevice.cb = Marshal.SizeOf(displayDevice);
while (NativeMethods.EnumDisplayDevices(null, i, ref displayDevice, 1))
{
result.Add(displayDevice);
i++;
}
return result;
}
public static List<DISPLAY_DEVICE> GetMonitors(string graphicsAdapter)
{
DISPLAY_DEVICE displayDevice = new DISPLAY_DEVICE();
List<DISPLAY_DEVICE> result = new List<DISPLAY_DEVICE>();
int i = 0;
displayDevice.cb = Marshal.SizeOf(displayDevice);
while (NativeMethods.EnumDisplayDevices(graphicsAdapter, i, ref displayDevice, 0))
{
result.Add(displayDevice);
i++;
}
return result;
}
public static List<DEVMODE> GetDeviceModes(string graphicsAdapter)
{
int i = 0;
DEVMODE devMode = new DEVMODE();
List<DEVMODE> result = new List<DEVMODE>();
while (NativeMethods.EnumDisplaySettings(graphicsAdapter, i, ref devMode))
{
result.Add(devMode);
i++;
}
return result;
}
}