1
실제 이름을 반환 할 때 몇 대의 모니터가 연결되어 있습니다 (예 : LEN L192p, IBM 190p).EnumDisplayDevices 반환 값은 일반 PnP 모니터입니다 - C#
How do I get the actual Monitor name? as seen in the resolution dialog
을하지만 난 그것을 실행할 때, 내가 잘못 식별을 얻을 :
이 질문에 여기 보았습니다. 그것은 내 랩톱을 감지하지만 사용하고있는 다른 두 화면 (LEN L192p, IBM 190p)은 감지되지 않고 대신 Generic PnP Monitor
을 작성합니다.
누구든지 문제를 알 수 있습니까?
및 코드 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Screens
{
class Program
{
[DllImport("user32.dll")]
public static extern bool EnumDisplayDevices(string lpDevice, uint iDevNum, ref DISPLAY_DEVICE lpDisplayDevice, uint dwFlags);
[Flags()]
public enum DisplayDeviceStateFlags : int
{
/// <summary>The device is part of the desktop.</summary>
AttachedToDesktop = 0x1,
MultiDriver = 0x2,
/// <summary>The device is part of the desktop.</summary>
PrimaryDevice = 0x4,
/// <summary>Represents a pseudo device used to mirror application drawing for remoting or other purposes.</summary>
MirroringDriver = 0x8,
/// <summary>The device is VGA compatible.</summary>
VGACompatible = 0x16,
/// <summary>The device is removable; it cannot be the primary display.</summary>
Removable = 0x20,
/// <summary>The device has more display modes than its output devices support.</summary>
ModesPruned = 0x8000000,
Remote = 0x4000000,
Disconnect = 0x2000000
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct DISPLAY_DEVICE
{
[MarshalAs(UnmanagedType.U4)]
public int cb;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string DeviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string DeviceString;
[MarshalAs(UnmanagedType.U4)]
public DisplayDeviceStateFlags StateFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string DeviceID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string DeviceKey;
}
static void Main(string[] args)
{
var device = new DISPLAY_DEVICE();
device.cb = Marshal.SizeOf(device);
try
{
for (uint id = 0; EnumDisplayDevices(null, id, ref device, 0); id++)
{
device.cb = Marshal.SizeOf(device);
EnumDisplayDevices(device.DeviceName, 0, ref device, 0);
device.cb = Marshal.SizeOf(device);
Console.WriteLine("id={0}, name={1}, devicestring={2}", id, device.DeviceName, device.DeviceString);
if (device.DeviceName == null || device.DeviceName == "") continue;
}
string x = Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(String.Format("{0}", ex.ToString()));
}
}
지금 장치 관리자를보고 그 내용을 보았습니다. 하지만 (제어판에서) 화면 해상도를 보면이 이름을 볼 수 있습니다. 이 이름을 얻는 방법이 있습니까? – user1386966
@ user1386966 나는 그렇게 생각하지 않는다. 적어도 나는 그것을 발견 할 수있다. – Ashigore