-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonitorInfo.cpp
More file actions
26 lines (22 loc) · 915 Bytes
/
MonitorInfo.cpp
File metadata and controls
26 lines (22 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "MonitorInfo.h"
#include <thread>
std::vector<SMonitorInfo> GetAllMonitorsInfo() {
std::vector<SMonitorInfo> monitors = {};
std::thread([&monitors] {
static HMODULE hUser32 = LoadLibraryA("user32.dll");
static auto pSetThreadDpiAwarenessContext = (PVOID(WINAPI*)(PVOID))GetProcAddress(hUser32, "SetThreadDpiAwarenessContext");
pSetThreadDpiAwarenessContext((PVOID)-3 /* DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE */);
EnumDisplayMonitors(nullptr, nullptr, [] (HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) -> BOOL {
((std::vector<SMonitorInfo>*)dwData)->push_back({
.hMonitor = hMonitor,
.hdcMonitor = hdcMonitor,
.left = lprcMonitor->left,
.top = lprcMonitor->top,
.width = lprcMonitor->right - lprcMonitor->left,
.height = lprcMonitor->bottom - lprcMonitor->top
});
return TRUE;
}, (LPARAM)&monitors);
}).join();
return monitors;
}