add C module to get the Windows display information

This commit is contained in:
Josh Holtrop committed 2013-11-24 20:34:36 -05:00
1 parent 15d9612d7e
commit 5575022ffc
2 files changed
+54 -2

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
/*
* Author: Josh Holtrop
* This Windows-specific module will get the screen size
* and return the number of monitors present.
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <windows.h>
void GetDisplaySize(int * width, int * height, int * num_monitors)
{
int w = 0;
int h = 0;
int n = 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 ((strcmp(dev.DeviceID, "") != 0) && (dev.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP))
{
HDC hdc = CreateDC(TEXT("DISPLAY"), dev.DeviceString, NULL, NULL);
if (hdc != NULL)
{
n++;
w += GetDeviceCaps(hdc, HORZRES);
int thisHeight = GetDeviceCaps(hdc, VERTRES);
/* assume monitors are all horizontally aligned */
if (thisHeight > h)
h = thisHeight;
}
}
}
/* only update width and height if we have valid data */
if (w != 0 && h != 0)
{
if (width != NULL)
*width = w;
if (height != NULL)
*height = h;
if (num_monitors != NULL)
*num_monitors = n;
}
}