From 0f4f802f841de2a7dc591be2005f397766d46baf Mon Sep 17 00:00:00 2001 From: fizzfang Date: Wed, 5 Feb 2025 16:54:59 +0800 Subject: [PATCH] Skip owned window with WS_EX_LAYERED attribute when capturing with GDI. When using GDI to capture windows, not only will the target window be captured, but all owned windows of the target window will also be captured, and the captured results of the owned windows will be drawn onto the captured result of target window. GDI (BitBlt or PrintWindow) cannot capture windows with WS_EX_LAYERED attribute, so when the owned window has this attribute, the area of the owned window in the result is black. After modification, if the owned window has the WS_EX_LAYERED attribute, it will not be captured or drawn. Bug: webrtc:394380765 Change-Id: I5f0c7d31809a353377b0aa52452634b46247af5f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/376360 Commit-Queue: Alexander Cooper Reviewed-by: Joe Downing Reviewed-by: Alexander Cooper Cr-Commit-Position: refs/heads/main@{#43851} --- modules/desktop_capture/win/window_capturer_win_gdi.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/desktop_capture/win/window_capturer_win_gdi.cc b/modules/desktop_capture/win/window_capturer_win_gdi.cc index bc3a762264..7872be7d70 100644 --- a/modules/desktop_capture/win/window_capturer_win_gdi.cc +++ b/modules/desktop_capture/win/window_capturer_win_gdi.cc @@ -365,6 +365,10 @@ WindowCapturerWinGdi::CaptureResults WindowCapturerWinGdi::CaptureFrame( for (auto it = owned_windows_.rbegin(); it != owned_windows_.rend(); it++) { HWND hwnd = *it; + LONG style = GetWindowLong(hwnd, GWL_EXSTYLE); + if (style & WS_EX_LAYERED) { + continue; + } if (owned_window_capturer_->SelectSource( reinterpret_cast(hwnd))) { CaptureResults results = owned_window_capturer_->CaptureFrame(