dwscr/displayinfo-win32.cc
josh 4ed97f09f6 added -W, -w, -h command line options, retabbed a couple files
git-svn-id: svn://anubis/dwscr/trunk@91 5bef9df8-b654-44bb-925b-0ff18baa8f8c
2008-11-13 02:49:11 +00:00

56 lines
1.3 KiB
C++

/* 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 <string>
#include <windows.h>
#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;
}