优化构建

This commit is contained in:
2023-10-24 20:25:03 +08:00
parent 4305a8cf1e
commit ac0eca92a9
9 changed files with 175 additions and 19 deletions

View File

@@ -1,10 +1,10 @@
#include "ScreenManager.h"
#include <Windows.h>
#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "Utils/StringUtil.h"
ScreenManager::ScreenManager()
{
@@ -19,6 +19,7 @@ void ScreenManager::UpdateDisplayInfo()
{
_UpdateDisplayDeviceList();
_UpdateMonitorInfoMap();
_UpdateDisplayAdapterList();
}
void ScreenManager::_UpdateDisplayDeviceList()
@@ -39,6 +40,35 @@ void ScreenManager::_UpdateDisplayDeviceList()
spdlog::info("=====GetInfoByEnumDisplayDevices end=====");
}
void ScreenManager::_UpdateDisplayAdapterList()
{
spdlog::info("=====_UpdateDisplayAdapterList start=====");
HRESULT hr = S_OK;
hr = CoInitialize(nullptr);
if (FAILED(hr)) {
spdlog::error("_UpdateDisplayAdapterList CoInitialize failed");
return;
}
IDXGIFactory7* dxgiFactory = nullptr;
hr = CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory));
if (FAILED(hr)) {
spdlog::error("CreateDXGIFactory1 failed");
CoUninitialize();
return;
}
UINT adapterIndex = 0;
IDXGIAdapter* adapter = nullptr;
while (dxgiFactory->EnumAdapters(adapterIndex, &adapter) != DXGI_ERROR_NOT_FOUND) {
_displayAdapterList.push_back(adapter); // 将 IDXGIAdapter 指针存储在容器中
adapterIndex++;
}
dxgiFactory->Release();
CoUninitialize();
}
BOOL ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
{
MONITORINFOEX monitorInfo;

View File

@@ -3,20 +3,23 @@
#include <map>
#include <Mmdeviceapi.h>
#include <dxgi1_6.h>
class ScreenManager
{
public:
ScreenManager();
~ScreenManager();
void UpdateDisplayInfo();
void UpdateDisplayInfo();
std::vector<DISPLAY_DEVICE> _displayDeviceList;
std::map<HMONITOR, MONITORINFOEX> _hMonitorInfoMap;
std::vector<IDXGIAdapter*> _displayAdapterList;
private:
void _UpdateDisplayDeviceList();
void _UpdateMonitorInfoMap();
void _UpdateDisplayAdapterList();
static BOOL CALLBACK EnumMonitorsProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData);
BOOL _EnumMonitorProc(HMONITOR hMonitor);
std::vector<DISPLAY_DEVICE> _displayDeviceList;
std::map<HMONITOR, MONITORINFOEX> _hMonitorInfoMap;
};