diff --git a/WinDevice/Utils/SysInfoUtil.cpp b/WinDevice/Utils/SysInfoUtil.cpp index 3bd1141..caf006f 100644 --- a/WinDevice/Utils/SysInfoUtil.cpp +++ b/WinDevice/Utils/SysInfoUtil.cpp @@ -158,19 +158,53 @@ int SysInfoUtil::GetInfoByEnumDisplayDevices() return 0; } +void SysInfoUtil::GetInfoByEnumDisplayDevicesA() +{ + DISPLAY_DEVICEA dd; + DEVMODEA dm; + for (int i = 0;; i++) { + ZeroMemory(&dd, sizeof(dd)); + dd.cb = sizeof(dd); + BOOL ret = (EnumDisplayDevicesA(NULL, i, &dd, 0)); + if (ret == FALSE) + break; + ZeroMemory(&dm, sizeof(dm)); + dm.dmSize = sizeof(dm); + if (EnumDisplaySettingsA(dd.DeviceName, ENUM_CURRENT_SETTINGS, &dm)) { + std::cout << "Device #" << i << " Information:" << std::endl; + std::cout << "Device Name: " << dd.DeviceName << std::endl; + std::cout << "Device String: " << dd.DeviceString << std::endl; + std::cout << "State: " << (dd.StateFlags & DISPLAY_DEVICE_ACTIVE ? "Active" : "Inactive") << std::endl; + std::cout << "Device ID: " << dd.DeviceID << std::endl; + std::cout << "Device Key: " << dd.DeviceKey << std::endl; + std::cout << std::endl; + } + } +} void SysInfoUtil::GetInfoByEnumDisplayMonitors() { wcout << "=====GetInfoByEnumDisplayMonitors start=====" << endl; // 枚举显示器 EnumDisplayMonitors(NULL, NULL, [](HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) -> BOOL { + // 获取显示器的设备名称 MONITORINFOEX monitorInfo; monitorInfo.cbSize = sizeof(MONITORINFOEX); if (GetMonitorInfo(hMonitor, &monitorInfo)) { - // 输出友好名称 - wcout << "szDevice:" << monitorInfo.szDevice << endl; - wcout << "right:" << monitorInfo.rcMonitor.right << endl; - wcout << "bottom:" << monitorInfo.rcMonitor.bottom << endl; + std::wcout << L"name: " << monitorInfo.szDevice << std::endl; + + // 获取显示器的屏幕区域 + std::wcout << L"rect: left(" << lprcMonitor->left << ", " << lprcMonitor->top + << "), right(" << lprcMonitor->right << ", " << lprcMonitor->bottom << ")" << std::endl; + + // 获取显示器的分辨率 + std::wcout << L"dpi: w=" << lprcMonitor->right - lprcMonitor->left + << ", h=" << lprcMonitor->bottom - lprcMonitor->top << std::endl; + + std::wcout << L"===================" << std::endl; } + + + return TRUE; }, 0); wcout << "=====GetInfoByEnumDisplayMonitors end=====" << endl; diff --git a/WinDevice/Utils/SysInfoUtil.h b/WinDevice/Utils/SysInfoUtil.h index b8fa183..e9cfb68 100644 --- a/WinDevice/Utils/SysInfoUtil.h +++ b/WinDevice/Utils/SysInfoUtil.h @@ -16,6 +16,8 @@ public: static int GetInfoByQueryDisplayConfig(); + static void GetInfoByEnumDisplayDevicesA(); + static int GetInfoByCfgmgr(); private: