众人拾柴火焰高,github给个star行不行?
open-traa/traa
traa
is a versatile project aimed at recording anything, anywhere. The primary focus is to provide robust solutions for various recording scenarios, making it a highly adaptable tool for multiple use cases.
在Windows中获取可进行屏幕共享捕获的窗口列表及其图标、缩略图
在Windows系统中,获取可进行屏幕共享捕获的窗口列表以及它们的图标和缩略图是一个复杂但有趣的过程。本文将详细介绍如何实现这一功能,涉及到的主要技术包括Windows API、C++编程和一些第三方库。
前置知识
在开始之前,您需要了解以下内容:
- Windows API:Windows API提供了大量的函数,用于与操作系统进行交互。
- C++编程:本文的示例代码使用C++编写。
- 第三方库:我们将使用
libyuv
库来处理图像缩放。
实现步骤
1. 包含必要的头文件
首先,我们需要包含一些必要的头文件,这些头文件提供了我们需要的函数和数据结构。
#include "base/devices/screen/desktop_geometry.h"
#include "base/devices/screen/enumerator.h"
#include "base/devices/screen/mouse_cursor.h"
#include "base/devices/screen/utils.h"
#include "base/devices/screen/win/capture_utils.h"
#include "base/devices/screen/win/cursor.h"
#include "base/devices/screen/win/scoped_object_gdi.h"
#include "base/log/logger.h"
#include "base/strings/string_trans.h"
#include "base/utils/win/version.h"
#include <libyuv/scale_argb.h>
#include <memory>
#include <string>
#include <stdlib.h>
#include <shellapi.h>
#include <windows.h>
2. 定义辅助函数
我们需要一些辅助函数来获取窗口属性、窗口文本、进程路径等。
获取窗口属性
typedef HRESULT(WINAPI *FuncDwmGetWindowAttribute)(HWND window, DWORD dwAttribute, PVOID pvAttribute, DWORD cbAttribute);
FuncDwmGetWindowAttribute helper_get_dwmapi_get_window_attribute() {
HINSTANCE dwmapi = LoadLibraryW(L"Dwmapi.dll");
if (dwmapi == nullptr) {
return nullptr;
}
FuncDwmGetWindowAttribute dwmapi_get_window_attribute =
(FuncDwmGetWindowAttribute)GetProcAddress(dwmapi, "DwmGetWindowAttribute");
if (dwmapi_get_window_attribute == nullptr) {
return nullptr;
}
return dwmapi_get_window_attribute;
}
获取窗口文本
int get_window_text_safe(HWND window, LPWSTR p_string, int cch_max_count) {
return ::InternalGetWindowText(window, p_string, cch_max_count);
}
获取进程路径
int get_window_process_path(HWND window, wchar_t *path, int max_count) {
DWORD process_id;
::GetWindowThreadProcessId(window, &process_id);
if (process_id == 0) {
return 0;
}
HANDLE process = ::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, process_id);
if (process == nullptr) {
return 0;
}
DWORD buffer_size = static_cast<DWORD>(max_count)