I am trying to use the EnumDisplayMonitors to create a dynamic array of each monitor and store the DISPLAY_DEVICE structure. Why is the below code not correct?
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;
};
}
Called using
ScreenArray monitorArray[15];
int i = 0;
EnumDisplayMonitors(NULL, NULL, MyInfoEnumProc, reinterpret_cast<LPARAM>(&monitorArray[i++]));
The first in the array (monitorArray[0]) returns correct information for the second monitor but monitorArray[1] is max values.
EDIT: Solved The method I used was just implementing a function I created:
MonitorArray *mA = reinterpret_cast<MonitorArray*>(dwData);
mA->addScreen(&iMonitor);
See Question&Answers more detail:os