【发布时间】:2014-10-24 04:28:42
【问题描述】:
我正在尝试使用 EnumDisplayMonitors 创建每个监视器的动态数组并存储 DISPLAY_DEVICE 结构。为什么下面的代码不正确?
BOOL CALLBACK MyInfoEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
MONITORINFOEX iMonitor;
iMonitor.cbSize = sizeof(MONITORINFOEX);
GetMonitorInfo(hMonitor, &iMonitor);
if (iMonitor.dwFlags == DISPLAY_DEVICE_MIRRORING_DRIVER)
{
return true;
}
else
{
*reinterpret_cast<ScreenArray*>(dwData) = ScreenArray(&iMonitor);
return true;
};
}
调用使用
ScreenArray monitorArray[15];
int i = 0;
EnumDisplayMonitors(NULL, NULL, MyInfoEnumProc, reinterpret_cast<LPARAM>(&monitorArray[i++]));
数组中的第一个 (monitorArray[0]) 返回第二个监视器的正确信息,但 monitorArray[1] 是最大值。
编辑:已解决 我使用的方法只是实现了我创建的一个函数:
MonitorArray *mA = reinterpret_cast<MonitorArray*>(dwData);
mA->addScreen(&iMonitor);
【问题讨论】:
-
EnumDisplayMonitors多次调用MyInfoEnumProc,每次在dwData中传递&monitorArray[0]。数组的其他元素从未被触及。
标签: c++ windows winapi callback