即使我有一个,EnumDisplayDevices 也会提供两个显示 [英] EnumDisplayDevices giving two Displays even though I have one

查看:26
本文介绍了即使我有一个,EnumDisplayDevices 也会提供两个显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Python 制作 Night Light 应用程序.我正在使用 Windows API 来使用 Gamma Ramp 来完成我的任务.我使用 user32.dll 中的 EnumDisplayDevicesW 来获取连接到我 PC 的显示器的信息和数量.

I was making an application for Night Light using Python. I'm using windows API for use of Gamma Ramp to accomplish my task. I used EnumDisplayDevicesW from user32.dll to get the information and number of displays connected to my PC.

我只有一台显示器连接到我的桌面,但输出提供了两台显示器的信息.

I have only one monitor connected to my desktop, but the output is giving information of two monitors.

这是我的代码.我正在使用 Python 并通过 ctypes 模块访问 WinAPI.

Here's my code. I'm using Python and accessing WinAPI through ctypes module.

import ctypes
from ctypes import wintypes


class DISPLAY_DEVICEW(ctypes.Structure):
    _fields_ = [
        ('cb', wintypes.DWORD),
        ('DeviceName', wintypes.WCHAR * 32),
        ('DeviceString', wintypes.WCHAR * 128),
        ('StateFlags', wintypes.DWORD),
        ('DeviceID', wintypes.WCHAR * 128),
        ('DeviceKey', wintypes.WCHAR * 128)
    ]

if __name__ == '__main__':
    EnumDisplayDevices = ctypes.windll.user32.EnumDisplayDevicesW       # get the function address
    EnumDisplayDevices.restype = ctypes.c_bool                          # set return type to BOOL

    displays = []           # to store display information
    i = 0                   # iteration variable for 'iDevNum'

    while True:
        INFO = DISPLAY_DEVICEW()            # struct object
        INFO.cb = ctypes.sizeof(INFO)       # setting 'cnSize' prior to calling 'EnumDisplayDevicesW'

        if not EnumDisplayDevices(None, i, ctypes.byref(INFO), 0):
            break       # break as soon as False is returned by 'EnumDisplayDevices'

        displays.append(INFO)       # append information to the list
        i += 1

    # display information in a sequential form
    for x in displays:
        print('DeviceName:\t\t', x.DeviceName)
        print("DeviceString:\t", x.DeviceString)
        print("StateFlags:\t\t", x.StateFlags)
        print("DeviceID:\t\t", x.DeviceID)
        print("DeviceKey:\t\t", x.DeviceKey)
        print(), print()

而代码返回的输出如下:-

And the output returned by the code is as follows:-

DeviceName:      \\.\DISPLAY1
DeviceString:    Intel(R) HD Graphics 510
StateFlags:      5
DeviceID:        PCI\VEN_8086&DEV_1902&SUBSYS_D0001458&REV_06
DeviceKey:       \Registry\Machine\System\CurrentControlSet\Control\Video\{C31A4E45-2A30-11EB-953B-92862920CE33}\0000


DeviceName:      \\.\DISPLAY2
DeviceString:    Intel(R) HD Graphics 510
StateFlags:      0
DeviceID:        PCI\VEN_8086&DEV_1902&SUBSYS_D0001458&REV_06
DeviceKey:       \Registry\Machine\System\CurrentControlSet\Control\Video\{C31A4E45-2A30-11EB-953B-92862920CE33}\0001

据我所知,第一个,即 \\.\DISPLAY1 是我的,但为什么需要第二个??

As far as I know, the first one, i.e, \\.\DISPLAY1 is mine one, but why there's a need for a second one??

我拥有一台配备标准三星显示器的台式电脑.

I own a Desktop PC with standard Samsung monitor.

任何帮助都会非常有帮助.提前致谢!

Any help will be very helpful. Thanks in advance!

推荐答案

我只有一台显示器连接到我的桌面,但输出提供了两台显示器的信息.

I have only one monitor connected to my desktop, but the output is giving information of two monitors.

运行此代码不会告诉您您有两个监视器",而是两个适配器".

Running this code does not tell you that you have two "monitors", but two "adapters".

根据EnumDisplayDevicesW:

要获取有关显示适配器的信息,请调用 EnumDisplayDevices,并将 lpDevice 设置为 NULL.例如,DISPLAY_DEVICE.DeviceString 包含适配器名称.

To get information on the display adapter, call EnumDisplayDevices with lpDevice set to NULL. For example, DISPLAY_DEVICE.DeviceString contains the adapter name.

要获取有关显示监视器的信息,首先调用 EnumDisplayDevices,并将 lpDevice 设置为 NULL.然后调用 EnumDisplayDevices,在第一次调用 EnumDisplayDevices 时将 lpDevice 设置为 DISPLAY_DEVICE.DeviceName,并将 iDevNum 设置为零.然后 DISPLAY_DEVICE.DeviceString 是监视器名称.

To obtain information on a display monitor, first call EnumDisplayDevices with lpDevice set to NULL. Then call EnumDisplayDevices with lpDevice set to DISPLAY_DEVICE.DeviceName from the first call to EnumDisplayDevices and with iDevNum set to zero. Then DISPLAY_DEVICE.DeviceString is the monitor name.

所以如果需要获取监控信息,需要调用:

So if you need to get the monitor information, you need to call:

EnumDisplayDevices(INFO.DeviceName,j,ctypes.byref(Monitor_INFO),0):

这是一个示例:

import ctypes
from ctypes import wintypes


class DISPLAY_DEVICEW(ctypes.Structure):
    _fields_ = [
        ('cb', wintypes.DWORD),
        ('DeviceName', wintypes.WCHAR * 32),
        ('DeviceString', wintypes.WCHAR * 128),
        ('StateFlags', wintypes.DWORD),
        ('DeviceID', wintypes.WCHAR * 128),
        ('DeviceKey', wintypes.WCHAR * 128)
    ]

if __name__ == '__main__':
    EnumDisplayDevices = ctypes.windll.user32.EnumDisplayDevicesW       # get the function address
    EnumDisplayDevices.restype = ctypes.c_bool                          # set return type to BOOL

    displays = []           # to store display information
    i = 0                   # iteration variable for 'iDevNum'
    j = 0
    while True:
        INFO = DISPLAY_DEVICEW()            # struct object
        INFO.cb = ctypes.sizeof(INFO)       # setting 'cnSize' prior to calling 'EnumDisplayDevicesW'
        Monitor_INFO = DISPLAY_DEVICEW()   
        Monitor_INFO.cb = ctypes.sizeof(Monitor_INFO)  
        if not EnumDisplayDevices(None, i, ctypes.byref(INFO), 0):
            break       # break as soon as False is returned by 'EnumDisplayDevices'
        #j = 0
        while EnumDisplayDevices(INFO.DeviceName,j,ctypes.byref(Monitor_INFO),0):
            print("monitor name:\t\t",Monitor_INFO.DeviceName,'\n\n')
            j+=1

        displays.append(INFO)       # append information to the list
        i += 1

    # display information in a sequential form
    for x in displays:
        print('DeviceName:\t\t', x.DeviceName)
        print("DeviceString:\t", x.DeviceString)
        print("StateFlags:\t\t", x.StateFlags)
        print("DeviceID:\t\t", x.DeviceID)
        print("DeviceKey:\t\t", x.DeviceKey)
        print(), print()

这篇关于即使我有一个,EnumDisplayDevices 也会提供两个显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆