-
Notifications
You must be signed in to change notification settings - Fork 0
/
MonitorController.cpp
56 lines (49 loc) · 1.65 KB
/
MonitorController.cpp
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// Created by Pierce on 3/27/2024.
//
#include "MonitorController.h"
MonitorController::MonitorController() {
POINT cursorPos;
GetCursorPos(&cursorPos);
hMonitor = MonitorFromPoint(cursorPos, MONITOR_DEFAULTTONEAREST);
monitorInfoEx.cbSize = sizeof(MONITORINFOEX);
GetMonitorInfo(hMonitor, &monitorInfoEx);
devMode.dmSize = sizeof(devMode);
EnumDisplaySettings(monitorInfoEx.szDevice, ENUM_CURRENT_SETTINGS, &devMode);
devModeRest = devMode;
DEVMODE dm = { 0 };
dm.dmSize = sizeof(dm);
for(int mode = 0; EnumDisplaySettings(monitorInfoEx.szDevice, mode, &dm ) != 0; mode++) {
int key = (int) dm.dmPelsWidth;
if (resolutions.count(key)) continue;
resolutions[key];
resolutions[key].push_back((int) dm.dmPelsHeight);
}
}
HMONITOR MonitorController::getMonitor() {
return hMonitor;
}
MONITORINFOEX MonitorController::getMonitorInfo() {
return monitorInfoEx;
}
DEVMODE MonitorController::getDeviceMode() {
return devMode;
}
std::map<int, std::vector<int>> MonitorController::getSupportedResolutions() {
return resolutions;
}
void MonitorController::resetChanges() {
ChangeDisplaySettingsEx(monitorInfoEx.szDevice, &devModeRest, nullptr, 0, nullptr);
}
long MonitorController::setResolution(int x, int y) {
if (this->resolutions.count(x) == 0) {
return -90;
}
std::vector<int> xVector = this->resolutions[x];
if (std::find(xVector.begin(), xVector.end(), y) == xVector.end()) {
return -90;
}
devMode.dmPelsWidth = x;
devMode.dmPelsHeight = y;
return ChangeDisplaySettingsEx(monitorInfoEx.szDevice, &devMode, nullptr, 0, nullptr);
}