blob: 8d742cda982e5dedfb55fc06f3e33f54f21a08af [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
Zijie He70fbbad2017-08-15 15:45:00 -070011#include "webrtc/modules/desktop_capture/window_finder_win.h"
Zijie Heb010a322017-08-07 15:25:01 -070012
13#include <windows.h>
14
15namespace webrtc {
16
Zijie He70fbbad2017-08-15 15:45:00 -070017WindowFinderWin::WindowFinderWin() = default;
18WindowFinderWin::~WindowFinderWin() = default;
19
20WindowId WindowFinderWin::GetWindowUnderPoint(DesktopVector point) {
Zijie Heb010a322017-08-07 15:25:01 -070021 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