java - 连接的显示器名称

标签 java c++ display

我正在开发一个使用附加显示器(Wacom 数位板)的应用程序。 我需要确定它的放置位置,但我从 Java 代码中收集到的 DisplayName 始终是 Display 0、Display 1 等... 我尝试使用小型 C++ 来获取系统显示:

void DumpDevice(const DISPLAY_DEVICE& dd, size_t nSpaceCount)
{   
    printf("%*sDevice Name: %s\n", nSpaceCount, "", dd.DeviceName);
    printf("%*sDevice String: %s\n", nSpaceCount, "", dd.DeviceString);
    printf("%*sState Flags: %x\n", nSpaceCount, "", dd.StateFlags);
    printf("%*sDeviceID: %s\n", nSpaceCount, "", dd.DeviceID);
    printf("%*sDeviceKey: ...%s\n\n", nSpaceCount, "", dd.DeviceKey + 42);
}

int main()
{
    DISPLAY_DEVICE dd;

    dd.cb = sizeof(DISPLAY_DEVICE);

    DWORD deviceNum = 0;
    while (EnumDisplayDevices(NULL, deviceNum, &dd, 0)){
        DumpDevice(dd, 0);
        DISPLAY_DEVICE newdd = { 0 };
        newdd.cb = sizeof(DISPLAY_DEVICE);
        DWORD monitorNum = 0;
        while (EnumDisplayDevices(dd.DeviceName, monitorNum, &newdd, 0))
        {
            DumpDevice(newdd, 4);
            monitorNum++;
        }
        puts("");
        deviceNum++;
    }

    system("pause");

    return 0;
}

(我从堆栈溢出的另一个答案中得到这段代码,但我不记得链接到它的页面)。

无论如何,输出真的没有用:

Device Name: \
Device String: I
State Flags: 5
DeviceID: P
DeviceKey: ...\

    Device Name: \
    Device String: G
    State Flags: 3
    DeviceID: M
    DeviceKey: ...\


Device Name: \
Device String: I
State Flags: 1
DeviceID: P
DeviceKey: ...\

    Device Name: \
    Device String: G
    State Flags: 3
    DeviceID: M
    DeviceKey: ...\


Device Name: \
Device String: I
State Flags: 1
DeviceID: P
DeviceKey: ...\

    Device Name: \
    Device String: G
    State Flags: 3
    DeviceID: M
    DeviceKey: ...\


Device Name: \
Device String: I
State Flags: 8000000
DeviceID: P
DeviceKey: ...\


Device Name: \
Device String: I
State Flags: 0
DeviceID: P
DeviceKey: ...\


Device Name: \
Device String: I
State Flags: 0
DeviceID: P
DeviceKey: ...\

有什么解决办法吗?

编辑:Java 应用程序需要所有这些,我正在使用 C++ 创建一个简单的包装,并使用 JNI 调用我的包装。如果存在一种更好的方法来执行此操作而不从 C++ 传递则更好。

最佳答案

我更改为 ANSII 字符集,现在输出如下(感谢 SirDarius 的提示):

Device Name: \\.\DISPLAY1
Device String: Intel(R) HD Graphics Family
State Flags: 5
DeviceID: PCI\VEN_8086&DEV_0A16&SUBSYS_05CB1028&REV_0B
DeviceKey: ...\Control\Video\{80DB7D25-0399-49FD-A13A-F5FEAD8FCC0B}\0000

    Device Name: \\.\DISPLAY1\Monitor0
    Device String: Generic PnP Monitor
    State Flags: 3
    DeviceID: MONITOR\AUO133D\{4d36e96e-e325-11ce-bfc1-08002be10318}\0003
    DeviceKey: ...\Control\Class\{4d36e96e-e325-11ce-bfc1-08002be10318}\0003


Device Name: \\.\DISPLAY2
Device String: Intel(R) HD Graphics Family
State Flags: 1
DeviceID: PCI\VEN_8086&DEV_0A16&SUBSYS_05CB1028&REV_0B
DeviceKey: ...\Control\Video\{80DB7D25-0399-49FD-A13A-F5FEAD8FCC0B}\0001

    Device Name: \\.\DISPLAY2\Monitor0
    Device String: Generic PnP Monitor
    State Flags: 3
    DeviceID: MONITOR\DELA0B9\{4d36e96e-e325-11ce-bfc1-08002be10318}\0004
    DeviceKey: ...\Control\Class\{4d36e96e-e325-11ce-bfc1-08002be10318}\0004


Device Name: \\.\DISPLAY3
Device String: Intel(R) HD Graphics Family
State Flags: 1
DeviceID: PCI\VEN_8086&DEV_0A16&SUBSYS_05CB1028&REV_0B
DeviceKey: ...\Control\Video\{80DB7D25-0399-49FD-A13A-F5FEAD8FCC0B}\0002

    Device Name: \\.\DISPLAY3\Monitor0
    Device String: Generic PnP Monitor
    State Flags: 3
    DeviceID: MONITOR\WAC1039\{4d36e96e-e325-11ce-bfc1-08002be10318}\0006
    DeviceKey: ...\Control\Class\{4d36e96e-e325-11ce-bfc1-08002be10318}\0006


Device Name: \\.\DISPLAY4
Device String: Intel(R) HD Graphics Family
State Flags: 8000000
DeviceID: PCI\VEN_8086&DEV_0A16&SUBSYS_05CB1028&REV_0B
DeviceKey: ...\Control\Video\{80DB7D25-0399-49FD-A13A-F5FEAD8FCC0B}\0003


Device Name: \\.\DISPLAY5
Device String: Intel(R) HD Graphics Family
State Flags: 8000000
DeviceID: PCI\VEN_8086&DEV_0A16&SUBSYS_05CB1028&REV_0B
DeviceKey: ...\Control\Video\{80DB7D25-0399-49FD-A13A-F5FEAD8FCC0B}\0004


Device Name: \\.\DISPLAY6
Device String: Intel(R) HD Graphics Family
State Flags: 8000000
DeviceID: PCI\VEN_8086&DEV_0A16&SUBSYS_05CB1028&REV_0B
DeviceKey: ...\Control\Video\{80DB7D25-0399-49FD-A13A-F5FEAD8FCC0B}\0005

如何查看显示器的友好名称,全部显示为 Generic PnP!

关于java - 连接的显示器名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34652839/

相关文章:

html - 图片在桌面和移动平台上显示不一样

java - Wicket excel 页面已过期

java - 在liferay hook中将自定义类导入到JSP

java - 为 JAXB.unmarshal() 提取 XML 节点的最简单方法是什么?

c++ - OpenGL 二维矩形未被渲染

c++ - 如何获取 C/C++ 项目中的所有数据类型大小和函数堆栈占用空间大小?

java - Math.random() 与 Random.nextInt(int)

c++ - 语句 “(void)startGuardBegin;” 的作用是什么?

html - 如何使 2 个子元素在没有偏移的情况下位于顶部?

html - 我有一个奇怪的 html 和 css 结构,如何让我的聊天消息与底部对齐?