From 50298ad6e881570b223e6284ce5ecbb1e4c04386 Mon Sep 17 00:00:00 2001 From: DevWiki Date: Tue, 10 Oct 2023 11:54:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A5=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E5=BC=95=E5=85=A5WinDevice=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ DeviceManager/CMakeLists.txt | 18 ++++++++++++--- DeviceManager/main.cpp | 2 ++ WinDevice/.gitignore | 1 + WinDevice/CMakeLists.txt | 33 +++++++++++++-------------- WinDevice/src/Video/ScreenManager.cpp | 16 ++++++------- 6 files changed, 44 insertions(+), 28 deletions(-) create mode 100644 WinDevice/.gitignore diff --git a/.gitignore b/.gitignore index 83485ad..f373d06 100644 --- a/.gitignore +++ b/.gitignore @@ -73,4 +73,6 @@ CMakeLists.txt.user* *.exe .vscode +.idea +.vs diff --git a/DeviceManager/CMakeLists.txt b/DeviceManager/CMakeLists.txt index ab794b6..bc3c480 100644 --- a/DeviceManager/CMakeLists.txt +++ b/DeviceManager/CMakeLists.txt @@ -9,13 +9,17 @@ set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# 设置源代码文件编码为UTF-8 +add_compile_options("$<$:/source-charset:utf-8>") + find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) # 添加sdplog目录 -include_directories(include/third_lib/spdlog) -# 添加WinDevice目录 -include_directories(../WinDevice) +include_directories(include/third_lib) + +# 添加WinDevice项目 +add_subdirectory(../WinDevice WinDevice) set(PROJECT_SOURCES main.cpp @@ -48,6 +52,14 @@ else() endif() target_link_libraries(DeviceManager PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) +# 链接WinDevice项目 +target_include_directories(DeviceManager PRIVATE + ../WinDevice +) +# 将WinDevice项目的头文件路径添加到DeviceManager项目中 +target_include_directories(DeviceManager PRIVATE + ../WinDevice/src # 根据实际路径进行修改 +) set_target_properties(DeviceManager PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com diff --git a/DeviceManager/main.cpp b/DeviceManager/main.cpp index fd3e533..03afd54 100644 --- a/DeviceManager/main.cpp +++ b/DeviceManager/main.cpp @@ -1,10 +1,12 @@ #include "mainwindow.h" #include +#include "Video/ScreenManager.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); + MainWindow w; w.show(); return a.exec(); diff --git a/WinDevice/.gitignore b/WinDevice/.gitignore new file mode 100644 index 0000000..1028905 --- /dev/null +++ b/WinDevice/.gitignore @@ -0,0 +1 @@ +/cmake-* \ No newline at end of file diff --git a/WinDevice/CMakeLists.txt b/WinDevice/CMakeLists.txt index 1cf4306..1b9b211 100644 --- a/WinDevice/CMakeLists.txt +++ b/WinDevice/CMakeLists.txt @@ -1,24 +1,23 @@ cmake_minimum_required(VERSION 3.12) -project(WinDevice) +project(WinDevice VERSION 0.1 LANGUAGES CXX) -# 添加主项目的源文件 -add_executable(WinDevice - -) +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) -# 设置头文件目录,包括spdlog头文件和功能模块的头文件目录 -target_include_directories(WinDevice PRIVATE - include/ - include/third_lib/ - src/Audio/ - src/Video/ - src/Utils/ -) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# 设置源代码文件编码为UTF-8 +add_compile_options("$<$:/source-charset:utf-8>") + +# 添加sdplog目录 +include_directories(include/third_lib) # 添加功能模块的源文件 -target_sources(WinDevice PRIVATE - src/Audio/*.cpp - src/Video/*.cpp - src/Utils/*.cpp +set(PROJECT_SOURCES + "src/Audio" + "src/Video" + "src/Utils" ) diff --git a/WinDevice/src/Video/ScreenManager.cpp b/WinDevice/src/Video/ScreenManager.cpp index 613b0b9..76576fe 100644 --- a/WinDevice/src/Video/ScreenManager.cpp +++ b/WinDevice/src/Video/ScreenManager.cpp @@ -46,33 +46,33 @@ BOOL ScreenManager::_EnumMonitorProc(HMONITOR hMonitor) monitorInfo.cbSize = sizeof(MONITORINFOEX); if (GetMonitorInfo(hMonitor, &monitorInfo)) { - // Ѻ + // 输出友好名称 spdlog::info("_UpdateMonitorInfoMap, szDevice:{0}, right:{1}, bottom:{2}", Wchar2String(monitorInfo.szDevice), monitorInfo.rcMonitor.right, monitorInfo.rcMonitor.bottom); } auto it = ScreenManager::_hMonitorInfoMap.find(hMonitor); if (it != ScreenManager::_hMonitorInfoMap.end()) { - // Ѿڣʾظ - // ﴦظ + // 键已经存在,表示存在重复 + // 在这里处理重复的情况 } else { ScreenManager::_hMonitorInfoMap.insert(std::make_pair(hMonitor, monitorInfo)); - // ڣʾûظ - // ﴦظ + // 键不存在,表示没有重复 + // 在这里处理非重复的情况 } DISPLAYCONFIG_TARGET_DEVICE_NAME targetDeviceName = {}; targetDeviceName.header.size = sizeof(targetDeviceName); - // ȡָ HMONITOR Ŀ豸Ϣ + // 获取指定 HMONITOR 的目标设备名称信息 if (DisplayConfigGetDeviceInfo(&targetDeviceName.header) == ERROR_SUCCESS) { spdlog::info("_UpdateMonitorInfoMap, monitorDevicePath:{0}, monitorFriendlyDeviceName:{1}", Wchar2String(targetDeviceName.monitorDevicePath), Wchar2String(targetDeviceName.monitorFriendlyDeviceName)); - // ȡָ HMONITOR ķֱϢ + // 获取指定 HMONITOR 的分辨率信息 DEVMODE dm; dm.dmSize = sizeof(DEVMODE); dm.dmDriverExtra = 0; @@ -101,7 +101,7 @@ BOOL CALLBACK ScreenManager::EnumMonitorsProc(HMONITOR hMonitor, HDC hdcMonitor, void ScreenManager::_UpdateMonitorInfoMap() { spdlog::info("=====GetInfoByEnumDisplayMonitors start====="); - // öʾ + // 枚举显示器 EnumDisplayMonitors(nullptr, nullptr, EnumMonitorsProc, reinterpret_cast(this)); spdlog::info("=====GetInfoByEnumDisplayMonitors end====="); }