File: hwnd_util.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (75 lines) | stat: -rw-r--r-- 2,978 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GFX_WIN_HWND_UTIL_H_
#define UI_GFX_WIN_HWND_UTIL_H_

#include <shobjidl.h>
#include <windows.h>

#include <wrl/client.h>

#include <optional>
#include <string>

#include "base/component_export.h"

namespace gfx {
class Size;
class Rect;

// A version of the GetClassNameW API that returns the class name in an
// std::wstring. An empty result indicates a failure to get the class name.
COMPONENT_EXPORT(GFX) std::wstring GetClassName(HWND hwnd);

// Useful for subclassing a HWND.  Returns the previous window procedure.
COMPONENT_EXPORT(GFX) WNDPROC SetWindowProc(HWND hwnd, WNDPROC wndproc);

// Pointer-friendly wrappers around Get/SetWindowLong(..., GWLP_USERDATA, ...)
// Returns the previously set value.
COMPONENT_EXPORT(GFX) void* SetWindowUserData(HWND hwnd, void* user_data);
COMPONENT_EXPORT(GFX) void* GetWindowUserData(HWND hwnd);

// Returns true if the specified window is the current active top window or one
// of its children.
COMPONENT_EXPORT(GFX) bool DoesWindowBelongToActiveWindow(HWND window);

// Returns true if the specified window is cloaked.  Windows 10 and later
// have cloaked windows which are windows with WS_VISIBLE attribute but not
// displayed.
COMPONENT_EXPORT(GFX) bool IsWindowCloaked(HWND hwnd);

// Returns true if we are interested in `hwnd` for purposes of occlusion
// calculation. We are interested in `hwnd` if it is a window that is
// visible, opaque, bounded, and not a popup or floating window. If we are
// interested in `hwnd`, and `window_rect` is not null, stores the window
// rectangle in `window_rect`.
COMPONENT_EXPORT(GFX)
bool IsWindowVisibleAndFullyOpaque(HWND hwnd, gfx::Rect* window_rect);

// Returns true if `window` is on the current virtual desktop, false if isn't,
// and std::nullopt if a COM method fails. Since this calls COM methods,
// it can only be called from a COM thread.
COMPONENT_EXPORT(GFX)
std::optional<bool> IsWindowOnCurrentVirtualDesktop(
    HWND window,
    Microsoft::WRL::ComPtr<IVirtualDesktopManager> virtual_desktop_manager);

// Sizes the window to have a window size of |pref|, then centers the window
// over |parent|, ensuring the window fits on screen.
COMPONENT_EXPORT(GFX)
void CenterAndSizeWindow(HWND parent, HWND window, const gfx::Size& pref);

// If |hwnd| is nullptr logs various thing and CHECKs. |last_error| must contain
// the result of ::GetLastError(), called immediately after CreateWindow().
COMPONENT_EXPORT(GFX) void CheckWindowCreated(HWND hwnd, DWORD last_error);

// Returns the window you can use to parent a top level window.
// Note that in some cases we create child windows not parented to its final
// container so in those cases you should pass true in |get_real_hwnd|.
COMPONENT_EXPORT(GFX) HWND GetWindowToParentTo(bool get_real_hwnd);

}  // namespace gfx

#endif  // UI_GFX_WIN_HWND_UTIL_H_