| 3266 | |
| 3267 | |
| 3268 | BOOL CALLBACK EnumMonitorProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM lParam) |
| 3269 | { |
| 3270 | MonitorInfoPackage &mip = *(MonitorInfoPackage *)lParam; // For performance and convenience. |
| 3271 | if (mip.monitor_number_to_find == COUNT_ALL_MONITORS) |
| 3272 | { |
| 3273 | ++mip.count; |
| 3274 | return TRUE; // Enumerate all monitors so that they can be counted. |
| 3275 | } |
| 3276 | if (!GetMonitorInfo(hMonitor, &mip.monitor_info_ex)) // Failed. Probably very rare. |
| 3277 | return FALSE; // Due to the complexity of needing to stop at the correct monitor number, do not continue. |
| 3278 | // In the unlikely event that the above fails when the caller wanted us to find the primary |
| 3279 | // monitor, the caller will think the primary is the previously found monitor (if any). |
| 3280 | // This is just documented here as a known limitation since this combination of circumstances |
| 3281 | // is probably impossible. |
| 3282 | ++mip.count; // So that caller can detect failure, increment only now that failure conditions have been checked. |
| 3283 | if (mip.monitor_number_to_find) // Caller gave a specific monitor number, so don't search for the primary monitor. |
| 3284 | { |
| 3285 | if (mip.count == mip.monitor_number_to_find) // Since the desired monitor has been found, must not continue. |
| 3286 | return FALSE; |
| 3287 | } |
| 3288 | else // Caller wants the primary monitor found. |
| 3289 | // MSDN docs are unclear that MONITORINFOF_PRIMARY is a bitwise value, but the name "dwFlags" implies so: |
| 3290 | if (mip.monitor_info_ex.dwFlags & MONITORINFOF_PRIMARY) |
| 3291 | return FALSE; // Primary has been found and "count" contains its number. Must not continue the enumeration. |
| 3292 | // Above assumes that it is impossible to not have a primary monitor in a system that has at least |
| 3293 | // one monitor. MSDN certainly implies this through multiple references to the primary monitor. |
| 3294 | // Otherwise, continue the enumeration: |
| 3295 | return TRUE; |
| 3296 | } |
| 3297 | |
| 3298 | |
| 3299 |
nothing calls this directly
no outgoing calls
no test coverage detected