EDN Admin
Well-known member
Greetings,
I am looking to enumerate the attached displays and their unique names as seen in the control panel. I am currently using the EnumDisplayDevices() method to get the available displays. The method works excellently for gathering attached displays and their device names (ex. \.DISPLAY1). However, for the sake of the user, I need to acquire the "Friendly" name of the display.
Below is a code sample enumerating a list of DISPLAY_DEVICE structs (I have them named as DisplayDevice). It loops until the first enumeration returns an error. The second enumeration should populate the device string with its name, but all I ever get is "Generic PnP Monitor" while Control Panel shows the actual name (ex. DELL G2410). The third enumeration is similar to the first, with the intent to recover the graphics device that the display is attached to.
public static void populateDevicesList()
{
devices = new List<DisplayDevice>();
bool error = false;
for(int devId = 0; !error; devId++)
{
try
{
//setup the device structure...
DisplayDevice device = new DisplayDevice();
device.cb = Marshal.SizeOf(typeof(DisplayDevice));
//Commence enumeration
error = EnumDisplayDevices(null, devId, ref device, 0) == 0;
ControlForm.debug_addDebugMessage("Enumerated Display Device: " + device.DeviceName + " @" + device.DeviceString);
//do it again for extra data?
bool extraerror = EnumDisplayDevices(device.DeviceName, 0, ref device, 0x00000001) == 0;
if(!extraerror)
{
ControlForm.debug_addDebugMessage("tInitializing device " + devId + " with name: " + device.DeviceString + "...");
EnumDisplayDevices(null, devId, ref device, 0);
devices.Add(device);
ControlForm.debug_addDebugMessage("ttAdded device: " + device.DeviceName + " Attached to: " + device.DeviceString);
}
}
catch(Exception)
{
ControlForm.debug_addDebugMessage("Exception during initialization");
error = true;
}
}
}
Is there a particular step that I am missing? Perhaps there is an alternative, using EDID or registry reading? I have not had any success with WMI or EnumDisplayMonitors() and GetMonitorInfo().
I find my question to be similar to this one, but I have not been able to resolve the issue. If you need any more information or code samples, please ask so I can provide.
Thank you in advance for any help you can provide.
View the full article
I am looking to enumerate the attached displays and their unique names as seen in the control panel. I am currently using the EnumDisplayDevices() method to get the available displays. The method works excellently for gathering attached displays and their device names (ex. \.DISPLAY1). However, for the sake of the user, I need to acquire the "Friendly" name of the display.
Below is a code sample enumerating a list of DISPLAY_DEVICE structs (I have them named as DisplayDevice). It loops until the first enumeration returns an error. The second enumeration should populate the device string with its name, but all I ever get is "Generic PnP Monitor" while Control Panel shows the actual name (ex. DELL G2410). The third enumeration is similar to the first, with the intent to recover the graphics device that the display is attached to.
public static void populateDevicesList()
{
devices = new List<DisplayDevice>();
bool error = false;
for(int devId = 0; !error; devId++)
{
try
{
//setup the device structure...
DisplayDevice device = new DisplayDevice();
device.cb = Marshal.SizeOf(typeof(DisplayDevice));
//Commence enumeration
error = EnumDisplayDevices(null, devId, ref device, 0) == 0;
ControlForm.debug_addDebugMessage("Enumerated Display Device: " + device.DeviceName + " @" + device.DeviceString);
//do it again for extra data?
bool extraerror = EnumDisplayDevices(device.DeviceName, 0, ref device, 0x00000001) == 0;
if(!extraerror)
{
ControlForm.debug_addDebugMessage("tInitializing device " + devId + " with name: " + device.DeviceString + "...");
EnumDisplayDevices(null, devId, ref device, 0);
devices.Add(device);
ControlForm.debug_addDebugMessage("ttAdded device: " + device.DeviceName + " Attached to: " + device.DeviceString);
}
}
catch(Exception)
{
ControlForm.debug_addDebugMessage("Exception during initialization");
error = true;
}
}
}
Is there a particular step that I am missing? Perhaps there is an alternative, using EDID or registry reading? I have not had any success with WMI or EnumDisplayMonitors() and GetMonitorInfo().
I find my question to be similar to this one, but I have not been able to resolve the issue. If you need any more information or code samples, please ask so I can provide.
Thank you in advance for any help you can provide.
View the full article