作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要帮助的关联PHYSICAL_MONITOR这是我从GetPhysicalMonitorsFromHMONITOR获得与显示器DISPLAY_DEVICE.DeviceID(如 “\?\DISPLAY#GSM59AB#5 932a802&1&UID261#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}”),这是从EnumDisplayDevices,旗EDD_GET_DEVICE_INTERFACE_NAME使用,或以某种方式从 DISPLAY_DEVICE.DeviceID 获取 PHYSICAL_MONITOR,反之亦然。
我需要将它们都关联起来,因为:
DWORD DispNum = 0;
DISPLAY_DEVICE DisplayDevice;
// Initialize DisplayDevice.
ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
DisplayDevice.cb = sizeof(DisplayDevice);
while ((EnumDisplayDevices(NULL, DispNum, &DisplayDevice, 0)))
{
std::wstring deviceName = DisplayDevice.DeviceName;
DISPLAY_DEVICE DisplayDeviceM;
ZeroMemory(&DisplayDeviceM, sizeof(DisplayDeviceM));
DisplayDeviceM.cb = sizeof(DisplayDeviceM);
int monitorIndex = 0;
while (EnumDisplayDevices(deviceName.c_str(), monitorIndex, &DisplayDeviceM, EDD_GET_DEVICE_INTERFACE_NAME))
{
std::wstring monitorID = DisplayDeviceM.DeviceID;
++monitorIndex;
}
DispNum++;
}
按照与此相同的顺序:
BOOL CALLBACK EnumProc2(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{
LPPHYSICAL_MONITOR pMons = NULL;
DWORD i, mcnt;
MONITORINFOEX mi;
ZeroMemory(&mi, sizeof(mi));
mi.cbSize = sizeof(mi);
GetMonitorInfo(hMonitor, &mi);
DISPLAY_DEVICE dd;
ZeroMemory(&dd, sizeof(dd));
dd.cb = sizeof(dd);
EnumDisplayDevices(mi.szDevice, 0, &dd, EDD_GET_DEVICE_INTERFACE_NAME);
monitorModelMnufac MdlManuf = findMonitorModelManufactFromEDID(dd.DeviceID);
if (!GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, &mcnt)) return TRUE;
pMons = (LPPHYSICAL_MONITOR)malloc(mcnt * sizeof(PHYSICAL_MONITOR));
if (GetPhysicalMonitorsFromHMONITOR(hMonitor, mcnt, pMons))
for (i = 0; i < mcnt; i++)
{
AddToMonHandles(pMons[i].hPhysicalMonitor, MdlManuf);
}
free(pMons);
return TRUE;
}
物理监视器 HANDLE 是 0、1、2 等等,所以我可以从“monitorIndex”制作 HANDLE,但我不确定这样做是否安全。
最佳答案
我找到了一些有用的信息,希望对您有所帮助。
...
while ((EnumDisplayDevices(NULL, DispNum, &DisplayDevice, 0)))
{
std::wstring deviceName = DisplayDevice.DeviceName;
DISPLAY_DEVICE DisplayDeviceM;
ZeroMemory(&DisplayDeviceM, sizeof(DisplayDeviceM));
DisplayDeviceM.cb = sizeof(DisplayDeviceM);
int monitorIndex = 0;
while (EnumDisplayDevices(deviceName.c_str(), monitorIndex, &DisplayDeviceM, EDD_GET_DEVICE_INTERFACE_NAME))
{
wcout << "deviceName:" << deviceName << endl;
std::wstring monitorID = DisplayDeviceM.DeviceID;
wcout <<"monitorID :"<< monitorID<< endl;
++monitorIndex;
}
DispNum++;
}
...
输出:
deviceName: \\.\DISPLAY1
然后使用
EnumDisplayMonitors
获取
HMONITOR
并将其用作
GetMonitorInfo
的参数.
static BOOL CALLBACK MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT lprcMonitor, LPARAM pData)
{
cout << "hmonitor:" << hMon << endl;
MONITORINFOEX mi;
mi.cbSize = sizeof(mi);
GetMonitorInfo(hMon, (LPMONITORINFO)&mi);
wcout << "deviceName: "<<mi.szDevice << endl;
DWORD cPhysicalMonitors;
BOOL bSuccess = GetNumberOfPhysicalMonitorsFromHMONITOR(hMon, &cPhysicalMonitors);
cout << "GetNumber: " << bSuccess << ", number of physical monitors: " << cPhysicalMonitors << endl;
LPPHYSICAL_MONITOR pPhysicalMonitors = (LPPHYSICAL_MONITOR)malloc(cPhysicalMonitors * sizeof(PHYSICAL_MONITOR));
bSuccess = GetPhysicalMonitorsFromHMONITOR(hMon, cPhysicalMonitors, pPhysicalMonitors);
cout << "GetPhysicalMonitor: " << bSuccess << endl
<< "Handle: " << pPhysicalMonitors->hPhysicalMonitor << endl
<< "Description: ";
wcout << (WCHAR*)(pPhysicalMonitors->szPhysicalMonitorDescription) << endl;;
D(pPhysicalMonitors->hPhysicalMonitor);
DestroyPhysicalMonitors(cPhysicalMonitors, pPhysicalMonitors);
free(pPhysicalMonitors);
cout << "---------------------------------------" << endl;
return TRUE;
}
...
EnumDisplayMonitors(0, 0, MonitorEnum, NULL);
输出:
deviceName: \\.\DISPLAY1
如果两个输出相同,则它们对应于同一个监视器。最后,我们可以使用得到的
HMONITOR
作为
GetPhysicalMonitorsFromHMONITOR
的参数,这样我们就可以得到
hPhysicalMonitor
我们需要。
关于c++ - 如何将 PHYSICAL_MONITOR 与监视器 DeviceID 关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63095216/
我是一名优秀的程序员,十分优秀!