From 0bf5a76da5d2c094403d34c5f4d119b34b4925bb Mon Sep 17 00:00:00 2001 From: DevWiki Date: Tue, 8 Oct 2024 19:30:14 +0800 Subject: [PATCH] add app screen capture --- WinDevice/CMakeLists.txt | 4 ++-- WinDevice/src/Video/AppWindowCapture.cpp | 5 +++++ WinDevice/src/Video/AppWindowCapture.h | 20 ++++++++++++++++++++ WinDevice/src/Video/ScreenCapture.cpp | 5 +++++ WinDevice/src/Video/ScreenCapture.h | 14 ++++++++++++++ WinDevice/src/Video/ScreenManager.cpp | 13 +++++++------ WinDevice/src/Video/VideoManager.cpp | 5 +++++ WinDevice/src/Video/VideoManager.h | 24 ++++++++++++++++++++++++ 8 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 WinDevice/src/Video/AppWindowCapture.cpp create mode 100644 WinDevice/src/Video/AppWindowCapture.h create mode 100644 WinDevice/src/Video/ScreenCapture.cpp create mode 100644 WinDevice/src/Video/ScreenCapture.h create mode 100644 WinDevice/src/Video/VideoManager.cpp create mode 100644 WinDevice/src/Video/VideoManager.h diff --git a/WinDevice/CMakeLists.txt b/WinDevice/CMakeLists.txt index da603a9..61bea8e 100644 --- a/WinDevice/CMakeLists.txt +++ b/WinDevice/CMakeLists.txt @@ -109,11 +109,11 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG") set(LIBRARY_OUTPUT_PATH "${OUTPUT_DIR}/debug") # 添加测试 - add_executable(WinDeviceTest "src/main.cpp" ${SOURCE_FILES}) + add_executable(WinDeviceTest WIN32 "src/main.cpp" ${SOURCE_FILES}) target_include_directories(WinDeviceTest PUBLIC $ PRIVATE ${Third_Include_DIR} ${Windows_Kits_UM_DIR} ${Windows_Kits_SHARED_DIR}) - target_link_libraries(WinDeviceTest PRIVATE ${DirectX_LIBS}) + target_link_libraries(WinDeviceTest PRIVATE ${DirectX_LIBS} user32 gdi32) set_target_properties(WinDeviceTest PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/${ARCH_DIR}/debug" LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/${ARCH_DIR}/debug" diff --git a/WinDevice/src/Video/AppWindowCapture.cpp b/WinDevice/src/Video/AppWindowCapture.cpp new file mode 100644 index 0000000..0a0dcb1 --- /dev/null +++ b/WinDevice/src/Video/AppWindowCapture.cpp @@ -0,0 +1,5 @@ +// +// Created by zyz on 2024/10/8. +// + +#include "AppWindowCapture.h" diff --git a/WinDevice/src/Video/AppWindowCapture.h b/WinDevice/src/Video/AppWindowCapture.h new file mode 100644 index 0000000..cad9c11 --- /dev/null +++ b/WinDevice/src/Video/AppWindowCapture.h @@ -0,0 +1,20 @@ +// +// Created by zyz on 2024/10/8. +// + +#ifndef WINDEVICE_APPWINDOWCAPTURE_H +#define WINDEVICE_APPWINDOWCAPTURE_H + +namespace WinDevice { + + class AppWindowCapture { + public: + AppWindowCapture(); + ~AppWindowCapture(); + void UpdateAppThumbnail(); + private: + + }; +} + +#endif //WINDEVICE_APPWINDOWCAPTURE_H diff --git a/WinDevice/src/Video/ScreenCapture.cpp b/WinDevice/src/Video/ScreenCapture.cpp new file mode 100644 index 0000000..7d8f1ad --- /dev/null +++ b/WinDevice/src/Video/ScreenCapture.cpp @@ -0,0 +1,5 @@ +// +// Created by zyz on 2024/10/8. +// + +#include "ScreenCapture.h" diff --git a/WinDevice/src/Video/ScreenCapture.h b/WinDevice/src/Video/ScreenCapture.h new file mode 100644 index 0000000..f40150a --- /dev/null +++ b/WinDevice/src/Video/ScreenCapture.h @@ -0,0 +1,14 @@ +// +// Created by zyz on 2024/10/8. +// + +#ifndef WINDEVICE_SCREENCAPTURE_H +#define WINDEVICE_SCREENCAPTURE_H + +namespace WinDevice { + class ScreenCapture { + + }; +} + +#endif //WINDEVICE_SCREENCAPTURE_H diff --git a/WinDevice/src/Video/ScreenManager.cpp b/WinDevice/src/Video/ScreenManager.cpp index 2bb8dc2..9a0d954 100644 --- a/WinDevice/src/Video/ScreenManager.cpp +++ b/WinDevice/src/Video/ScreenManager.cpp @@ -84,7 +84,8 @@ void WinDevice::ScreenManager::_UpdateDisplayAdapterList() BOOL WinDevice::ScreenManager::_EnumMonitorProc(HMONITOR hMonitor) { - MONITORINFOEX monitorInfo; + HRESULT result; + MONITORINFOEX monitorInfo; monitorInfo.cbSize = sizeof(MONITORINFOEX); if (GetMonitorInfo(hMonitor, &monitorInfo)) { @@ -109,7 +110,8 @@ BOOL WinDevice::ScreenManager::_EnumMonitorProc(HMONITOR hMonitor) targetDeviceName.header.size = sizeof(targetDeviceName); // 获取指定 HMONITOR 的目标设备名称信息 - if (DisplayConfigGetDeviceInfo(&targetDeviceName.header) == ERROR_SUCCESS) + result = DisplayConfigGetDeviceInfo(&targetDeviceName.header); + if (result == ERROR_SUCCESS) { spdlog::info("_UpdateMonitorInfoMap, monitorDevicePath:{0}, monitorFriendlyDeviceName:{1}", WinDevice::Wchar2String(targetDeviceName.monitorDevicePath), WinDevice::Wchar2String(targetDeviceName.monitorFriendlyDeviceName)); @@ -118,19 +120,18 @@ BOOL WinDevice::ScreenManager::_EnumMonitorProc(HMONITOR hMonitor) DEVMODE dm; dm.dmSize = sizeof(DEVMODE); dm.dmDriverExtra = 0; - - if (EnumDisplaySettingsA((LPCSTR)targetDeviceName.monitorDevicePath, ENUM_CURRENT_SETTINGS, &dm) != 0) + if (EnumDisplaySettingsA((LPCSTR)targetDeviceName.monitorDevicePath, ENUM_CURRENT_SETTINGS, &dm)) { spdlog::info("Resolution:{0}x{1}", dm.dmPelsWidth, dm.dmPelsHeight); } else { - Log::error("Failed to get display resolution."); + Log::error("Failed to get display resolution"); } } else { - spdlog::error("Failed to get display device info."); + spdlog::error("Failed to get display device info, error:{0}", result); } return TRUE; } diff --git a/WinDevice/src/Video/VideoManager.cpp b/WinDevice/src/Video/VideoManager.cpp new file mode 100644 index 0000000..f8626b6 --- /dev/null +++ b/WinDevice/src/Video/VideoManager.cpp @@ -0,0 +1,5 @@ +// +// Created by zyz on 2024/10/8. +// + +#include "VideoManager.h" diff --git a/WinDevice/src/Video/VideoManager.h b/WinDevice/src/Video/VideoManager.h new file mode 100644 index 0000000..9e4d79b --- /dev/null +++ b/WinDevice/src/Video/VideoManager.h @@ -0,0 +1,24 @@ +// +// Created by zyz on 2024/10/8. +// + +#ifndef WINDEVICE_VIDEOMANAGER_H +#define WINDEVICE_VIDEOMANAGER_H + +#include +#include + +namespace WinDevice { + class VideoManager { + public: + VideoManager(); + ~VideoManager(); + + private: + BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam); + void _UpdateAppThumnbail(); + }; +} + + +#endif //WINDEVICE_VIDEOMANAGER_H