https://blog.youkuaiyun.com/xpg4321/article/details/112357480 介绍了如何截屏
因为录制可能需要录制窗口,这里介绍如何枚举mac屏幕的窗口。
1.定义保存窗口信息的结构
struct WindowPoint {
int x;
int y;
};
struct MousePoint {
WindowPoint Position;
WindowPoint HotSpot;
};
struct Window {
uint32_t Handle{0};
WindowPoint Position;
WindowPoint Size;
// Name will always be lower case. It is converted to lower case internally by the library for comparisons
char Name[256] = {0};
};
uint32_t Handle{0} 窗口句柄类似windows的HWND,
WindowPoint Position; 窗口的位置
WindowPoint Size; 窗口的大小
2.获取显示区域个数
CGDisplayCount count=0;
CGGetActiveDisplayList(0, 0, &count);
std::vector<CGDirectDisplayID> displays;
displays.resize(count);
CGGetActiveDisplayList(count, displays.data(), &count);
主要考虑扩展屏平
3.遍历显示区域获取缩放因子
auto xscale=1.0f;
auto yscale = 1.0f;
for(auto i = 0; i < count; i++) {
//only include non-mirrored displays
i

本文详细介绍了如何在Mac上通过编程枚举屏幕上的窗口,并获取指定窗口的信息,包括窗口的位置、大小等。首先定义了保存窗口信息的结构体,接着获取显示区域个数和缩放因子,然后遍历窗口获取窗口个数,最后通过窗口名称查找并返回窗口信息。
最低0.47元/天 解锁文章
1273

被折叠的 条评论
为什么被折叠?



