我有两个常规显示器和三个连接到 Windows pc 的投影仪的设置。在我的 win32 程序中,我需要唯一标识每个监视器并为每个监视器存储信息,以便即使在计算机重新启动后我也可以检索存储的信息。
该EnumDisplayDevices似乎重新启动计算机后返回不同的设备订单。还有GetPhysicalMonitorsFromHMONITOR它至少给了我显示器的名称。但是,我的投影机需要序列号之类的东西,因为它们是相同的型号。我怎样才能获得这样一个唯一的标识符?
编辑:这是我在阅读用户Anders的回答后提出的解决方案(谢谢!):
DISPLAY_DEVICEA dispDevice;
ZeroMemory(&dispDevice, sizeof(dispDevice));
dispDevice.cb = sizeof(dispDevice);
DWORD screenID;
while (EnumDisplayDevicesA(NULL, screenID, &dispDevice, 0))
{
// important: make copy of DeviceName
char name[sizeof(dispDevice.DeviceName)];
strcpy(name, dispDevice.DeviceName);
if (EnumDisplayDevicesA(name, 0, &dispDevice, EDD_GET_DEVICE_INTERFACE_NAME))
{
// at this point dispDevice.DeviceID contains a unique identifier for the monitor
}
++screenID;
}
Run Code Online (Sandbox Code Playgroud)