Skip to content

Instantly share code, notes, and snippets.

@kaimingguo
Created April 15, 2020 19:51
Show Gist options
  • Save kaimingguo/f812ab420772c7f09e8bfd733c849345 to your computer and use it in GitHub Desktop.
Save kaimingguo/f812ab420772c7f09e8bfd733c849345 to your computer and use it in GitHub Desktop.
Win32 API multi-monitor display information
#include <windows.h>
#include <iostream>
#include <vector>
struct ScreenArray {
std::vector<RECT> Monitors;
static BOOL CALLBACK MonitorEnumProc(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data) {
MONITORINFOEX mi = {0};
mi.cbSize = sizeof(MONITORINFOEX);
GetMonitorInfo(monitor, &mi);
if (mi.dwFlags == DISPLAY_DEVICE_MIRRORING_DRIVER) {
std::cout << "Using mirroring driver for multi-screen." << std::endl;
} else {
auto p = reinterpret_cast<ScreenArray *>(data);
p->Monitors.push_back(*rect);
}
return TRUE;
}
ScreenArray() {
Monitors.empty();
EnumDisplayMonitors(nullptr, nullptr, MonitorEnumProc, (LPARAM)this);
}
};
@kaimingguo
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment