优化构建
This commit is contained in:
@@ -4,6 +4,9 @@ cmake_minimum_required(VERSION 3.12)
|
||||
# 设置项目名称和版本,以及编程语言
|
||||
project(WinDevice VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
# 允许 Windows 导出所有符号
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
|
||||
|
||||
# 设置C++标准
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
@@ -49,4 +52,25 @@ set(THIRD_LIB_DIR ${CMAKE_SOURCE_DIR}/include/third_lib)
|
||||
target_include_directories(WinDevice PRIVATE
|
||||
include/third_lib
|
||||
src
|
||||
)
|
||||
)
|
||||
|
||||
# 设置库文件输出目录相对于 WinDevice 项目的根目录
|
||||
set(LIB_OUTPUT_DIR "${CMAKE_SOURCE_DIR}/lib")
|
||||
# 设置库的输出路径
|
||||
set_target_properties(WinDevice PROPERTIES
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${LIB_OUTPUT_DIR} # 设置静态库输出路径
|
||||
LIBRARY_OUTPUT_DIRECTORY ${LIB_OUTPUT_DIR} # 设置动态链接库输出路径
|
||||
)
|
||||
|
||||
# 设置发布目录,例如 "install" 文件夹
|
||||
set(INSTALL_DIR "${CMAKE_SOURCE_DIR}/install")
|
||||
|
||||
# 在发布阶段将库文件安装到指定目录
|
||||
install(TARGETS WinDevice
|
||||
ARCHIVE DESTINATION "${INSTALL_DIR}/lib" # 安装静态库文件
|
||||
LIBRARY DESTINATION "${INSTALL_DIR}/lib" # 安装动态链接库文件
|
||||
)
|
||||
|
||||
target_link_libraries(WinDevice PRIVATE dxguid)
|
||||
|
||||
target_compile_definitions(WinDevice PRIVATE -DWINDEVICE_EXPORTS)
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user