gpt4 book ai didi

c++ - 如何在 Win32 API 中从屏幕捕获中排除某些窗口?

转载 作者:行者123 更新时间:2023-12-03 09:23:41 32 4
gpt4 key购买 nike

我想捕获桌面并排除被捕获的应用程序窗口。

我的窗口创建如下:

m_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE | WS_EX_LAYERED,
g_lpszClassName, NULL, WS_THICKFRAME,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL,
_WPModule.GetHInstance(), NULL);

我捕获屏幕如下:

HWND    hWndCapture     = ::GetDesktopWindow();
HDC hdcScreen = ::GetDC(hWndCapture);
HDC hdcMem = ::CreateCompatibleDC(hdcScreen);

::BitBlt(
hdcMem,
0,
0,
Width, //width of region of interest
Height, //height of region of interest
hdcScreen,
X, //left staring point for capture
Y, //top staring point for capture
SRCCOPY);

我找到了以下链接Excluding certain windows from screen capture但它没有给出 I.E 8 及更高版本的解决方案。我没有找到针对此问题发布的任何其他解决方案。

最佳答案

我知道这个问题已经很老了,但我遇到了同样的问题,而且很难找到任何与此相关的信息。

Windows 10 版本 2004(内部版本 10.0.19041)以来,SetWindowDisplayAffinity API已扩展为包含名为 WDA_EXCLUDEFROMCAPTURE (0x00000011) 的标志。这将从使用 BitBlt

捕获的图像中删除窗口

The window is displayed only on a monitor. Everywhere else, the window does not appear at all.One use for this affinity is for windows that show video recording controls, so that the controls are not included in the capture.

Introduced in Windows 10 Version 2004. See remarks about compatibility regarding previous versions of Windows.

对于 2004 年之前的版本,它将使用现有的 WDA_MONITOR 标志。

我已经使用桌面屏幕截图对此进行了测试,我不确定如果您使用窗口 DC 会发生什么。

所以我想一个可能的解决方案是:

// get window handle
m_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE | WS_EX_LAYERED,
g_lpszClassName, NULL, WS_THICKFRAME,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL,
_WPModule.GetHInstance(), NULL);

BOOL result = SetWindowDisplayAffinity(m_hWnd, WDA_EXCLUDEFROMCAPTURE);

// do bitblt stuff

关于c++ - 如何在 Win32 API 中从屏幕捕获中排除某些窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25664989/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com