add C module to get the Windows display information
This commit is contained in:
parent
15d9612d7e
commit
5575022ffc
@ -26,7 +26,7 @@ task :default do
|
|||||||
"modules/gl3n/gl3n",
|
"modules/gl3n/gl3n",
|
||||||
"modules/glamour/glamour",
|
"modules/glamour/glamour",
|
||||||
].each do |dir|
|
].each do |dir|
|
||||||
sources += Dir["#{dir}/**/*.d"]
|
sources += Dir["#{dir}/**/*.{d,c}"]
|
||||||
end
|
end
|
||||||
sources << "build/obj2d/logoobj.d"
|
sources << "build/obj2d/logoobj.d"
|
||||||
env["D_IMPORT_PATH"] += [
|
env["D_IMPORT_PATH"] += [
|
||||||
@ -38,8 +38,9 @@ task :default do
|
|||||||
"modules/glamour",
|
"modules/glamour",
|
||||||
"build/obj2d",
|
"build/obj2d",
|
||||||
]
|
]
|
||||||
|
env["CFLAGS"] += ["-Wall", "-std=gnu99"]
|
||||||
env["DFLAGS"] += ["-fversion=Derelict3", "-fversion=gl3n", "-fversion=SDLImage"]
|
env["DFLAGS"] += ["-fversion=Derelict3", "-fversion=gl3n", "-fversion=SDLImage"]
|
||||||
env["LDFLAGS"] += ["-static-libgcc"]
|
env["LDFLAGS"] += ["-static-libgcc", "-mwindows"]
|
||||||
env.build_root = "build"
|
env.build_root = "build"
|
||||||
env.Obj2D("build/obj2d/logoobj.d", "model/gentex-logo.obj")
|
env.Obj2D("build/obj2d/logoobj.d", "model/gentex-logo.obj")
|
||||||
env.Program("gss", sources)
|
env.Program("gss", sources)
|
||||||
|
51
src/displayinfo.c
Normal file
51
src/displayinfo.c
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user