bug report: enum all display devices (#8745)

This commit is contained in:
Andrey Nekrasov
2020-12-25 12:49:58 +03:00
committed by GitHub
parent ff74ef4a42
commit 0c300194dc
2 changed files with 23 additions and 26 deletions

View File

@@ -171,6 +171,7 @@ namespace FancyZonesUtils
} }
typedef BOOL(WINAPI* GetDpiForMonitorInternalFunc)(HMONITOR, UINT, UINT*, UINT*); typedef BOOL(WINAPI* GetDpiForMonitorInternalFunc)(HMONITOR, UINT, UINT*, UINT*);
std::wstring GetDisplayDeviceId(const std::wstring& device, std::unordered_map<std::wstring, DWORD>& displayDeviceIdxMap) std::wstring GetDisplayDeviceId(const std::wstring& device, std::unordered_map<std::wstring, DWORD>& displayDeviceIdxMap)
{ {
DISPLAY_DEVICE displayDevice{ .cb = sizeof(displayDevice) }; DISPLAY_DEVICE displayDevice{ .cb = sizeof(displayDevice) };

View File

@@ -5,38 +5,33 @@
int report(std::wostream& os) int report(std::wostream& os)
{ {
struct capture
{
std::wostream* os = nullptr;
};
auto callback = [](HMONITOR monitor, HDC, RECT*, LPARAM prm) -> BOOL { auto callback = [](HMONITOR monitor, HDC, RECT*, LPARAM prm) -> BOOL {
std::wostream& os = *(std::wostream*)prm; std::wostream& os = *((capture*)prm)->os;
MONITORINFOEX mi; MONITORINFOEX mi;
mi.cbSize = sizeof(mi); mi.cbSize = sizeof(mi);
if (GetMonitorInfo(monitor, &mi))
if (GetMonitorInfoW(monitor, &mi))
{ {
os << "GetMonitorInfo OK\n"; os << "GetMonitorInfo OK\n";
DISPLAY_DEVICE displayDevice = { sizeof(displayDevice) }; DISPLAY_DEVICE displayDevice = { sizeof(displayDevice) };
if (EnumDisplayDevices(mi.szDevice, 0, &displayDevice, 1)) DWORD i = 0;
while (EnumDisplayDevicesW(mi.szDevice, i++, &displayDevice, EDD_GET_DEVICE_INTERFACE_NAME))
{ {
if (displayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) const bool active = displayDevice.StateFlags & DISPLAY_DEVICE_ACTIVE;
{ const bool mirroring = displayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER;
os << "EnumDisplayDevices OK[MIRRORING_DRIVER]: \n" os << "EnumDisplayDevices OK:\n"
<< "\tDeviceID = " << displayDevice.DeviceID << '\n' << "\tMirroring = " << mirroring << '\n'
<< "\tDeviceKey = " << displayDevice.DeviceKey << '\n' << "\tActive = " << active << '\n'
<< "\tDeviceName = " << displayDevice.DeviceName << '\n' << "\tDeviceID = " << displayDevice.DeviceID << '\n'
<< "\tDeviceString = " << displayDevice.DeviceString << '\n'; << "\tDeviceKey = " << displayDevice.DeviceKey << '\n'
} << "\tDeviceName = " << displayDevice.DeviceName << '\n'
else << "\tDeviceString = " << displayDevice.DeviceString << '\n';
{
os << "EnumDisplayDevices OK:\n"
<< "\tDeviceID = " << displayDevice.DeviceID << '\n'
<< "\tDeviceKey = " << displayDevice.DeviceKey << '\n'
<< "\tDeviceName = " << displayDevice.DeviceName << '\n'
<< "\tDeviceString = " << displayDevice.DeviceString << '\n';
}
}
else
{
auto message = get_last_error_message(GetLastError());
os << "EnumDisplayDevices FAILED: " << (message.has_value() ? message.value() : L"") << '\n';
} }
} }
else else
@@ -46,8 +41,9 @@ int report(std::wostream& os)
} }
return TRUE; return TRUE;
}; };
capture c;
if (EnumDisplayMonitors(nullptr, nullptr, callback, (LPARAM)&os)) c.os = &os;
if (EnumDisplayMonitors(nullptr, nullptr, callback, (LPARAM)&c))
{ {
os << "EnumDisplayMonitors OK\n"; os << "EnumDisplayMonitors OK\n";
} }