/* Author: Josh Holtrop * DornerWorks screensaver * This Windows-specific module will get the screen size * and return the number of monitors present. Right now the * screensaver will only work properly with two identically * sized monitors... */ #include #include #include "displayinfo.h" static int numMonitors = 0; void getDisplaySize(int * width, int * height) { std::string nullStr = ""; int w = 0; int h = 0; /* loop through the display devices to get their dimensions */ for (int i = 0; i < 10; i++) { DISPLAY_DEVICE dev; dev.cb = sizeof(DISPLAY_DEVICE); if (!EnumDisplayDevices(NULL, i, &dev, 0)) break; /* we only want real display devices to matter */ if (dev.DeviceID != nullStr) { HDC hdc = CreateDC(TEXT("DISPLAY"), dev.DeviceString, NULL, NULL); if (hdc != NULL) { numMonitors++; w += GetDeviceCaps(hdc, HORZRES); int thisHeight = GetDeviceCaps(hdc, VERTRES); if (thisHeight > h) h = thisHeight; } } } /* only update width and height if we have valid data */ if (w != 0 && h != 0) { *width = w; *height = h; } } int getNumMonitors() { return numMonitors; }