From 45ca8b8d196338ff9c96b3269bc4b7115d35b91b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 27 Aug 2017 22:42:23 +0200 Subject: [PATCH] Win32: Add HMONITOR to monitor data --- src/win32_monitor.c | 33 +++++++++++++++++++++++++++++++++ src/win32_platform.h | 1 + 2 files changed, 34 insertions(+) diff --git a/src/win32_monitor.c b/src/win32_monitor.c index 06e0e0cf..2aaec482 100644 --- a/src/win32_monitor.c +++ b/src/win32_monitor.c @@ -33,6 +33,27 @@ #include +// 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 // static _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter, @@ -41,6 +62,8 @@ static _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter, _GLFWmonitor* monitor; char* name; HDC dc; + DEVMODEW dm; + RECT rect; if (display) name = _glfwCreateUTF8FromWideStringWin32(display->DeviceString); @@ -78,6 +101,16 @@ static _GLFWmonitor* createMonitor(DISPLAY_DEVICEW* adapter, 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; } diff --git a/src/win32_platform.h b/src/win32_platform.h index 340b1ebb..0cc524d6 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -299,6 +299,7 @@ typedef struct _GLFWlibraryWin32 // typedef struct _GLFWmonitorWin32 { + HMONITOR handle; // This size matches the static size of DISPLAY_DEVICE.DeviceName WCHAR adapterName[32]; WCHAR displayName[32];