c# - 获取与显示设置中找到的匹配的显示名称

标签 c# wpf

在编写 WPF 应用程序时,我想获取在标准 Windows 显示设置对话框中找到的显示名称。我试过 WMI 查询 Win32_DesktopMonitor 和 System.Windows.Forms.Screen.AllScreens。

标准窗口显示设置列表中显示的名称是:

Mobile PC Display
DELL 2407WFP

Win32_DesktopMonitor 提供以下内容(已删除无关信息):

DISPLAY 1
Caption = Generic PnP Monitor
CreationClassName = Win32_DesktopMonitor
Description = Generic PnP Monitor
DeviceID = DesktopMonitor1
MonitorManufacturer = (Standard monitor types)
MonitorType = Generic PnP Monitor
Name = Generic PnP Monitor
PNPDeviceID = DISPLAY\DELA017\5&2F0149CC&0&UID1078064

DISPLAY 2
Caption = Generic PnP Monitor
CreationClassName = Win32_DesktopMonitor
Description = Generic PnP Monitor
DeviceID = DesktopMonitor2
MonitorManufacturer = (Standard monitor types)
MonitorType = Generic PnP Monitor
Name = Generic PnP Monitor
PNPDeviceID = DISPLAY\CMO1720\4&164FD10C&0&UID67568640

System.Windows.Forms.Screen.AllScreens 提供了一个设备列表(去除了不相关的信息):

DISPLAY 1
DeviceName = \\.\DISPLAY1

DISPLAY 2
DeviceName = \\.\DISPLAY3

显然,我应该能够将 DeviceName、DeviceID 或 PNPDeviceID 与其他地方的列表进行交叉引用以获取名称,不是吗?

请不要为此打扰我,我用谷歌搜索了我能想到的所有内容,但我找到的只是关于 AllScreens 和 Win32_DesktopMonitor 的信息,但没有找到我们在标准 Windows 显示设置对话框中看到的显示名称。

非常感谢。

最佳答案

看起来有人在 MSDN Forums 上问过这个完全相同的问题.

其中有两个相关的答案,我将在此处复制:

I am not sure exactly what you mean by monitor name, the unique monitor name? If when you call EnumDisplayDevices to enumerate the monitor you can specify the following flag: EDD_GET_DEVICE_INTERFACE_NAME then in the DeviceID field of the DISPLAY_DEVICE structure you will see the unique monitor name.

其次是:

Thanks, your solution was almost 100% there. The only thing I needed to add was a second call to EnumDisplayDevices and passing in the DeviceName returned from the first call. Then the DeviceName is populated with the Monitor's name and not the Video card. Perfect!

我自己没有这样做,所以我无法验证它是否有效,但根据 MSDN 线程的 OP 说它对他有效,这似乎令人鼓舞。

关于c# - 获取与显示设置中找到的匹配的显示名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7486485/

相关文章:

c# - 规范模式与扩展方法?

wpf - 使用 MultiBinding 的字符串格式?

c# - 将本地数据库放在 Visual Studio 解决方案中的什么位置?

c# - 如何在 datagridviewcell 上绘制自定义控件?

c# - 如何在 LINQ 查询中指定范围变量的类型?

c# - 设置 Cursor.Position "half"- 有效(从一台显示器到另一台显示器)

c# - 如何为附加属性设置动画?

wpf - 使用 MVVM 更改 ContentControl WPF 的内容?

wpf - Prism :壳之间的导航?

c# - 使用c#登录mysql