我正在开发一个使用额外显示器(Wacom平板电脑)的应用程序。 我需要确定它的放置位置,但我从java代码收集的DisplayName总是显示0,显示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 ++的情况下做到这一点更好。
答案 0 :(得分:2)
我改为ANSII charset,现在输出如下(感谢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!