blob: 9f87106a30c4a008aa4ad74b8afbc24f1b09a2ce [file] [log] [blame]
Zijie Heb010a322017-08-07 15:25:01 -07001/*
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/desktop_capture/window_finder_win.h"
Zijie Heb010a322017-08-07 15:25:01 -070012
13#include <windows.h>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/ptr_util.h"
Zijie He77b7a1d2017-09-01 15:51:14 -070016
Zijie Heb010a322017-08-07 15:25:01 -070017namespace webrtc {
18
Zijie He70fbbad2017-08-15 15:45:00 -070019WindowFinderWin::WindowFinderWin() = default;
20WindowFinderWin::~WindowFinderWin() = default;
21
22WindowId WindowFinderWin::GetWindowUnderPoint(DesktopVector point) {
Zijie Heb010a322017-08-07 15:25:01 -070023 HWND window = WindowFromPoint(POINT { point.x(), point.y() });
24 if (!window) {
25 return kNullWindowId;
26 }
27
28 // The difference between GA_ROOTOWNER and GA_ROOT can be found at
29 // https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/Hirr_DkuZdw.
30 // In short, we should use GA_ROOT, since we only care about the root window
31 // but not the owner.
32 window = GetAncestor(window, GA_ROOT);
33 if (!window) {
34 return kNullWindowId;
35 }
36
37 return reinterpret_cast<WindowId>(window);
38}
39
Zijie He77b7a1d2017-09-01 15:51:14 -070040// static
41std::unique_ptr<WindowFinder> WindowFinder::Create(
42 const WindowFinder::Options& options) {
43 return rtc::MakeUnique<WindowFinderWin>();
44}
45
Zijie Heb010a322017-08-07 15:25:01 -070046} // namespace webrtc