我如何获得实际的监视器的名字吗?如图中所示的分辨率对话框 [英] How do I get the actual Monitor name? as seen in the resolution dialog
问题描述
我试图抓住友好名称我的系统上的显示器。我使用C#。
我曾尝试屏幕
,它只是给了我 //./ DisplayXX
。我也曾尝试都 Win32_DesktopMonitor
和 EnumDisplayDevices
,他们都让我的变化//。 / DisplayXX
或通用显示器
,而我知道我的显示名称是的SyncMaster
和 SM2333T
。
现在的Windows知道这些监视器,并将其显示在设备和打印机与正确的名称的窗口,也是在对话框中设置的位置和分辨率。
我在哪里可以抓住从这些名字?我特地在注册表中,不能似乎找到他们,所以任何帮助将是巨大的。
解决方案:
打电话时 EnumDisplayDevices
第二次我又设置 iDevNum
来标识,这意味着我是想我的问题是从错误的地方获取数据,然后,我换成0这和它完美的作品,请参阅下面为code。
无功装置=新DISPLAY_DEVICE();
device.cb = Marshal.SizeOf(设备);
尝试
{
为(UINT ID = 0; EnumDisplayDevices(空,编号,参考设备,0);编号++)
{
Console.WriteLine(的String.Format({0},{1},{2},{3},{4},{5},编号device.DeviceName,device.DeviceString,device.StateFlags,设备。的DeviceID,device.DeviceKey));
Console.WriteLine();
device.cb = Marshal.SizeOf(设备); EnumDisplayDevices(device.DeviceName,0,参考设备,0); Console.WriteLine(的String.Format({0},{1},{2},{3},{4},{5},编号device.DeviceName,device.DeviceString,device.StateFlags,设备。的DeviceID,device.DeviceKey));
device.cb = Marshal.SizeOf(设备); device.cb = Marshal.SizeOf(设备);
返回;
} }
}
赶上(异常前)
{
Console.WriteLine(的String.Format({0},ex.ToString()));
}
在你收到了 DisplayDevice.DeviceName
如 //./ DisplayX
从 EnumDisplayDevices
,你应该叫'EnumDisplayDevices第二次,这次提供DisplayDevice.DeviceName'你从$ p了$ pvious电话为 lpDevice
,0为 iDevNum
。然后,你就必须在监视器名称 DisplayDevice.DeviceString
。
I am trying to grab the friendly name for the monitors on my system. I am using C#.
I have tried Screen
, which just gives me //./DisplayXX
. I have also tried both Win32_DesktopMonitor
and EnumDisplayDevices
, they all give me variations of //./DisplayXX
OR Generic Monitor
, whereas I know my displays names are SyncMaster
and SM2333T
.
Now Windows knows what these monitors are, displays them in the Devices and Printers windows with the correct names, and also in the dialog for setting location and resolution.
Where can I grab these names from? I have looked in the registry and cant seem to find them, so any help will be great.
SOLUTION:
The issue I had was when calling EnumDisplayDevices
the second time I was setting iDevNum
to id again, which meant I was trying to grab data from the wrong place, I then replaced this with 0, and it works perfectly, see below for the code.
var device = new DISPLAY_DEVICE();
device.cb = Marshal.SizeOf(device);
try
{
for (uint id = 0; EnumDisplayDevices(null, id, ref device, 0); id++)
{
Console.WriteLine(String.Format("{0}, {1}, {2}, {3}, {4}, {5}", id, device.DeviceName, device.DeviceString, device.StateFlags, device.DeviceID, device.DeviceKey));
Console.WriteLine();
device.cb = Marshal.SizeOf(device);
EnumDisplayDevices(device.DeviceName, 0, ref device, 0);
Console.WriteLine(String.Format("{0}, {1}, {2}, {3}, {4}, {5}", id, device.DeviceName, device.DeviceString, device.StateFlags, device.DeviceID, device.DeviceKey));
device.cb = Marshal.SizeOf(device);
device.cb = Marshal.SizeOf(device);
return;
}
}
}
catch (Exception ex)
{
Console.WriteLine(String.Format("{0}", ex.ToString()));
}
After you get a DisplayDevice.DeviceName
like //./DisplayX
from EnumDisplayDevices
, you are supposed to call 'EnumDisplayDevices' a second time, this time providing the 'DisplayDevice.DeviceName' that you got from the previous call as lpDevice
, and '0' as iDevNum
. Then you'll have the monitor name in DisplayDevice.DeviceString
.
这篇关于我如何获得实际的监视器的名字吗?如图中所示的分辨率对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!