Zijie He | b010a32 | 2017-08-07 15:25:01 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Zijie He | 70fbbad | 2017-08-15 15:45:00 -0700 | [diff] [blame^] | 11 | #include "webrtc/modules/desktop_capture/window_finder_win.h" |
Zijie He | b010a32 | 2017-08-07 15:25:01 -0700 | [diff] [blame] | 12 | |
| 13 | #include <windows.h> |
| 14 | |
| 15 | namespace webrtc { |
| 16 | |
Zijie He | 70fbbad | 2017-08-15 15:45:00 -0700 | [diff] [blame^] | 17 | WindowFinderWin::WindowFinderWin() = default; |
| 18 | WindowFinderWin::~WindowFinderWin() = default; |
| 19 | |
| 20 | WindowId WindowFinderWin::GetWindowUnderPoint(DesktopVector point) { |
Zijie He | b010a32 | 2017-08-07 15:25:01 -0700 | [diff] [blame] | 21 | HWND window = WindowFromPoint(POINT { point.x(), point.y() }); |
| 22 | if (!window) { |
| 23 | return kNullWindowId; |
| 24 | } |
| 25 | |
| 26 | // The difference between GA_ROOTOWNER and GA_ROOT can be found at |
| 27 | // https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/Hirr_DkuZdw. |
| 28 | // In short, we should use GA_ROOT, since we only care about the root window |
| 29 | // but not the owner. |
| 30 | window = GetAncestor(window, GA_ROOT); |
| 31 | if (!window) { |
| 32 | return kNullWindowId; |
| 33 | } |
| 34 | |
| 35 | return reinterpret_cast<WindowId>(window); |
| 36 | } |
| 37 | |
| 38 | } // namespace webrtc |