-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonitors.cpp
65 lines (50 loc) · 1.44 KB
/
Monitors.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
57
58
59
60
61
62
63
64
65
#include "Monitors.h"
Monitors::Monitors()
{
EnumDisplayMonitors(0, 0, MonitorEnum, (LPARAM)this);
}
BOOL CALLBACK Monitors::MonitorEnum(HMONITOR _hMon, HDC _hdc, LPRECT _lprcMonitor, LPARAM _pData)
{
Monitors* pThis = reinterpret_cast<Monitors*>(_pData);
pThis->hMonitors.push_back(_hMon);
pThis->hdcMonitors.push_back(_hdc);
pThis->rcMonitors.push_back(*_lprcMonitor);
pThis->iMonitors.push_back(pThis->hdcMonitors.size());
return TRUE;
}
bool Monitors::GetMonitorInfoId(UINT _id, RECT& _monitor)
{
Monitors monitors;
if (_id > monitors.iMonitors.size() - 1) {
wcout << _T("Error - problem with monitor ") + to_wstring(_id) << endl;
_id = 0;
}
_monitor = monitors.rcMonitors[_id];
return true;
}
bool Monitors::GetMonitorInfoPrimary(RECT& _monitor)
{
MONITORINFO monitorInfo = { 0 };
monitorInfo.cbSize = sizeof(monitorInfo);
HMONITOR hMonitor = MonitorFromWindow(GetDesktopWindow(), MONITOR_DEFAULTTONULL);
if (!hMonitor)
return false;
if (!GetMonitorInfo(hMonitor, &monitorInfo))
return false;
_monitor = monitorInfo.rcMonitor;
return true;
}
bool Monitors::GetMonitorInfoMouse(RECT& _monitor)
{
POINT mouse;
::GetCursorPos(&mouse);
MONITORINFO monitorInfo = { 0 };
monitorInfo.cbSize = sizeof(monitorInfo);
HMONITOR hMonitor = MonitorFromPoint(mouse, MONITOR_DEFAULTTONULL);
if (!hMonitor)
return false;
if (!GetMonitorInfo(hMonitor, &monitorInfo))
return false;
_monitor = monitorInfo.rcMonitor;
return true;
}