Win32: Add HMONITOR to monitor data

This commit is contained in:
Camilla Löwy 2017-08-27 22:42:23 +02:00
parent 58a247b26d
commit 45ca8b8d19
2 changed files with 34 additions and 0 deletions

View File

@ -33,6 +33,27 @@
#include <malloc.h> #include <malloc.h>
// Callback for EnumDisplayMonitors in createMonitor
//
static BOOL CALLBACK monitorCallback(HMONITOR handle,
HDC dc,
RECT* rect,
LPARAM data)
{
MONITORINFOEXW mi;
ZeroMemory(&mi, sizeof(mi));
mi.cbSize = sizeof(mi);
if (GetMonitorInfoW(handle, (MONITORINFO*) &mi))
{
_GLFWmonitor* monitor = (_GLFWmonitor*) data;
if (wcscmp(mi.szDevice, monitor->win32.adapterName) == 0)
monitor->win32.handle = handle;
}
return TRUE;
}
// Create monitor from an adapter and (optionally) a display // Create monitor from an adapter and (optionally) a display
// //
static _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter, static _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter,
@ -41,6 +62,8 @@ static _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter,
_GLFWmonitor* monitor; _GLFWmonitor* monitor;
char* name; char* name;
HDC dc; HDC dc;
DEVMODEW dm;
RECT rect;
if (display) if (display)
name = _glfwCreateUTF8FromWideStringWin32(display->DeviceString); name = _glfwCreateUTF8FromWideStringWin32(display->DeviceString);
@ -78,6 +101,16 @@ static _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter,
NULL, NULL); NULL, NULL);
} }
ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(dm);
EnumDisplaySettingsW(adapter->DeviceName, ENUM_CURRENT_SETTINGS, &dm);
rect.left = dm.dmPosition.x;
rect.top = dm.dmPosition.y;
rect.right = dm.dmPosition.x + dm.dmPelsWidth;
rect.bottom = dm.dmPosition.y + dm.dmPelsHeight;
EnumDisplayMonitors(NULL, &rect, monitorCallback, (LPARAM) monitor);
return monitor; return monitor;
} }

View File

@ -299,6 +299,7 @@ typedef struct _GLFWlibraryWin32
// //
typedef struct _GLFWmonitorWin32 typedef struct _GLFWmonitorWin32
{ {
HMONITOR handle;
// This size matches the static size of DISPLAY_DEVICE.DeviceName // This size matches the static size of DISPLAY_DEVICE.DeviceName
WCHAR adapterName[32]; WCHAR adapterName[32];
WCHAR displayName[32]; WCHAR displayName[32];