1
1
#pragma once
2
2
#include " ReportMonitorInfo.h"
3
3
#include < Windows.h>
4
+ #include < filesystem>
4
5
#include " ../../../src/common/utils/winapi_error.h"
6
+ using namespace std ;
5
7
6
- int report (std::wostream& os)
8
+ namespace
7
9
{
8
- struct capture
10
+ int buildMonitorInfoReport (std::wostream& os)
9
11
{
10
- std::wostream* os = nullptr ;
11
- };
12
+ struct capture
13
+ {
14
+ std::wostream* os = nullptr ;
15
+ };
12
16
13
- auto callback = [](HMONITOR monitor, HDC, RECT*, LPARAM prm) -> BOOL {
14
- std::wostream& os = *((capture*)prm)->os ;
15
- MONITORINFOEX mi;
16
- mi.cbSize = sizeof (mi);
17
+ auto callback = [](HMONITOR monitor, HDC, RECT*, LPARAM prm) -> BOOL {
18
+ std::wostream& os = *((capture*)prm)->os ;
19
+ MONITORINFOEX mi;
20
+ mi.cbSize = sizeof (mi);
17
21
18
- if (GetMonitorInfoW (monitor, &mi))
19
- {
20
- os << " GetMonitorInfo OK\n " ;
21
- DISPLAY_DEVICE displayDevice = { sizeof (displayDevice) };
22
+ if (GetMonitorInfoW (monitor, &mi))
23
+ {
24
+ os << " GetMonitorInfo OK\n " ;
25
+ DISPLAY_DEVICE displayDevice = { sizeof (displayDevice) };
22
26
23
- DWORD i = 0 ;
24
- while (EnumDisplayDevicesW (mi.szDevice , i++, &displayDevice, EDD_GET_DEVICE_INTERFACE_NAME))
27
+ DWORD i = 0 ;
28
+ while (EnumDisplayDevicesW (mi.szDevice , i++, &displayDevice, EDD_GET_DEVICE_INTERFACE_NAME))
29
+ {
30
+ const bool active = displayDevice.StateFlags & DISPLAY_DEVICE_ACTIVE;
31
+ const bool mirroring = displayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER;
32
+ os << " EnumDisplayDevices OK:\n "
33
+ << " \t Mirroring = " << mirroring << ' \n '
34
+ << " \t Active = " << active << ' \n '
35
+ << " \t DeviceID = " << displayDevice.DeviceID << ' \n '
36
+ << " \t DeviceKey = " << displayDevice.DeviceKey << ' \n '
37
+ << " \t DeviceName = " << displayDevice.DeviceName << ' \n '
38
+ << " \t DeviceString = " << displayDevice.DeviceString << ' \n ' ;
39
+ }
40
+ }
41
+ else
25
42
{
26
- const bool active = displayDevice.StateFlags & DISPLAY_DEVICE_ACTIVE;
27
- const bool mirroring = displayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER;
28
- os << " EnumDisplayDevices OK:\n "
29
- << " \t Mirroring = " << mirroring << ' \n '
30
- << " \t Active = " << active << ' \n '
31
- << " \t DeviceID = " << displayDevice.DeviceID << ' \n '
32
- << " \t DeviceKey = " << displayDevice.DeviceKey << ' \n '
33
- << " \t DeviceName = " << displayDevice.DeviceName << ' \n '
34
- << " \t DeviceString = " << displayDevice.DeviceString << ' \n ' ;
43
+ auto message = get_last_error_message (GetLastError ());
44
+ os << " GetMonitorInfo FAILED: " << (message.has_value () ? message.value () : L" " ) << ' \n ' ;
35
45
}
46
+ return TRUE ;
47
+ };
48
+ capture c;
49
+ c.os = &os;
50
+ if (EnumDisplayMonitors (nullptr , nullptr , callback, (LPARAM)&c))
51
+ {
52
+ os << " EnumDisplayMonitors OK\n " ;
36
53
}
37
54
else
38
55
{
39
56
auto message = get_last_error_message (GetLastError ());
40
- os << " GetMonitorInfo FAILED: " << (message.has_value () ? message.value () : L" " ) << ' \n ' ;
57
+ os << " EnumDisplayMonitors FAILED: " << (message.has_value () ? message.value () : L" " ) << ' \n ' ;
41
58
}
42
- return TRUE ;
43
- };
44
- capture c;
45
- c.os = &os;
46
- if (EnumDisplayMonitors (nullptr , nullptr , callback, (LPARAM)&c))
59
+ return 0 ;
60
+ }
61
+ }
62
+
63
+ void reportMonitorInfo (const filesystem::path& tmpDir)
64
+ {
65
+ auto monitorReportPath = tmpDir;
66
+ monitorReportPath.append (" monitor-report-info.txt" );
67
+
68
+ try
69
+ {
70
+ wofstream monitorReport (monitorReportPath);
71
+ monitorReport << " GetSystemMetrics = " << GetSystemMetrics (SM_CMONITORS) << ' \n ' ;
72
+ buildMonitorInfoReport (monitorReport);
73
+ }
74
+ catch (std::exception & ex)
47
75
{
48
- os << " EnumDisplayMonitors OK \n " ;
76
+ printf ( " Failed to report monitor info. %s \n " , ex. what ()) ;
49
77
}
50
- else
78
+ catch (...)
51
79
{
52
- auto message = get_last_error_message (GetLastError ());
53
- os << " EnumDisplayMonitors FAILED: " << (message.has_value () ? message.value () : L" " ) << ' \n ' ;
80
+ printf (" Failed to report monitor info\n " );
54
81
}
55
- return 0 ;
56
- }
82
+ }
0 commit comments