add app screen capture

This commit is contained in:
DevWiki 2024-10-08 19:30:14 +08:00
parent d784fc6570
commit 0bf5a76da5
8 changed files with 82 additions and 8 deletions

View File

@ -109,11 +109,11 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG")
set(LIBRARY_OUTPUT_PATH "${OUTPUT_DIR}/debug") 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 target_include_directories(WinDeviceTest
PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src> PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
PRIVATE ${Third_Include_DIR} ${Windows_Kits_UM_DIR} ${Windows_Kits_SHARED_DIR}) 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 set_target_properties(WinDeviceTest PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/${ARCH_DIR}/debug" ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/${ARCH_DIR}/debug"
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/${ARCH_DIR}/debug" LIBRARY_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}/${ARCH_DIR}/debug"

View File

@ -0,0 +1,5 @@
//
// Created by zyz on 2024/10/8.
//
#include "AppWindowCapture.h"

View File

@ -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

View File

@ -0,0 +1,5 @@
//
// Created by zyz on 2024/10/8.
//
#include "ScreenCapture.h"

View File

@ -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

View File

@ -84,7 +84,8 @@ void WinDevice::ScreenManager::_UpdateDisplayAdapterList()
BOOL WinDevice::ScreenManager::_EnumMonitorProc(HMONITOR hMonitor) BOOL WinDevice::ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
{ {
MONITORINFOEX monitorInfo; HRESULT result;
MONITORINFOEX monitorInfo;
monitorInfo.cbSize = sizeof(MONITORINFOEX); monitorInfo.cbSize = sizeof(MONITORINFOEX);
if (GetMonitorInfo(hMonitor, &monitorInfo)) if (GetMonitorInfo(hMonitor, &monitorInfo))
{ {
@ -109,7 +110,8 @@ BOOL WinDevice::ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
targetDeviceName.header.size = sizeof(targetDeviceName); targetDeviceName.header.size = sizeof(targetDeviceName);
// 获取指定 HMONITOR 的目标设备名称信息 // 获取指定 HMONITOR 的目标设备名称信息
if (DisplayConfigGetDeviceInfo(&targetDeviceName.header) == ERROR_SUCCESS) result = DisplayConfigGetDeviceInfo(&targetDeviceName.header);
if (result == ERROR_SUCCESS)
{ {
spdlog::info("_UpdateMonitorInfoMap, monitorDevicePath:{0}, monitorFriendlyDeviceName:{1}", spdlog::info("_UpdateMonitorInfoMap, monitorDevicePath:{0}, monitorFriendlyDeviceName:{1}",
WinDevice::Wchar2String(targetDeviceName.monitorDevicePath), WinDevice::Wchar2String(targetDeviceName.monitorFriendlyDeviceName)); WinDevice::Wchar2String(targetDeviceName.monitorDevicePath), WinDevice::Wchar2String(targetDeviceName.monitorFriendlyDeviceName));
@ -118,19 +120,18 @@ BOOL WinDevice::ScreenManager::_EnumMonitorProc(HMONITOR hMonitor)
DEVMODE dm; DEVMODE dm;
dm.dmSize = sizeof(DEVMODE); dm.dmSize = sizeof(DEVMODE);
dm.dmDriverExtra = 0; dm.dmDriverExtra = 0;
if (EnumDisplaySettingsA((LPCSTR)targetDeviceName.monitorDevicePath, ENUM_CURRENT_SETTINGS, &dm))
if (EnumDisplaySettingsA((LPCSTR)targetDeviceName.monitorDevicePath, ENUM_CURRENT_SETTINGS, &dm) != 0)
{ {
spdlog::info("Resolution:{0}x{1}", dm.dmPelsWidth, dm.dmPelsHeight); spdlog::info("Resolution:{0}x{1}", dm.dmPelsWidth, dm.dmPelsHeight);
} }
else else
{ {
Log::error("Failed to get display resolution."); Log::error("Failed to get display resolution");
} }
} }
else else
{ {
spdlog::error("Failed to get display device info."); spdlog::error("Failed to get display device info, error:{0}", result);
} }
return TRUE; return TRUE;
} }

View File

@ -0,0 +1,5 @@
//
// Created by zyz on 2024/10/8.
//
#include "VideoManager.h"

View File

@ -0,0 +1,24 @@
//
// Created by zyz on 2024/10/8.
//
#ifndef WINDEVICE_VIDEOMANAGER_H
#define WINDEVICE_VIDEOMANAGER_H
#include <minwindef.h>
#include <windef.h>
namespace WinDevice {
class VideoManager {
public:
VideoManager();
~VideoManager();
private:
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
void _UpdateAppThumnbail();
};
}
#endif //WINDEVICE_VIDEOMANAGER_H