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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
use crate::*;
use *;
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-ischild)\]
/// IsChild
///
/// Determines whether a window is a child window or descendant window of a specified parent window.
/// A child window is the direct descendant of a specified parent window if that parent window is in the chain of parent windows;
/// the chain of parent windows leads from the original overlapped or pop-up window to the child window.
///
/// ### Example
/// ```rust
/// # use hwnd::*;
/// # use std::ptr::*;
/// assert!(!is_child(get_desktop_window(), null_mut()));
/// # let _ = is_child(get_desktop_window(), !42usize as HWND);
/// # assert!(!is_child(get_desktop_window(), get_desktop_window()));
/// # assert!(!is_child(get_desktop_window(), get_shell_window()));
/// ```
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-isguithread)\]
/// IsGUIThread\(FALSE\)
///
/// Determines whether the calling thread is already a GUI thread.
///
/// ### Example
/// ```rust
/// # use hwnd::*;
/// # if false {
/// debug_assert!(!is_gui_thread(), "don't do I/O on the GUI thread");
/// let huge_file = std::fs::read("...").unwrap();
/// # }
/// #
/// # let _ = is_gui_thread(); // unit tests likely converted this to a GUI thread, but it's not guaranteed.
/// # std::thread::spawn(|| assert!(!is_gui_thread())).join();
/// ```
///
/// ### See Also
/// * [convert_to_gui_thread]
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-isguithread)\]
/// IsGUIThread\(TRUE\)
///
/// Convert the thread to a GUI thread.
///
/// ### Errors
/// * [ERROR::NOT_ENOUGH_MEMORY]
///
/// ### Example
/// ```rust
/// # use hwnd::*;
/// # let _ = is_gui_thread(); // unit tests likely converted this to a GUI thread, but it's not guaranteed.
/// std::thread::spawn(|| {
/// assert!(!is_gui_thread());
/// convert_to_gui_thread().unwrap();
/// assert!(is_gui_thread());
/// }).join();
/// ```
///
/// ### See Also
/// * [is_gui_thread]
// DO NOT DEFINE: IsHungAppWindow
// "[This function is not intended for general use. It may be altered or unavailable in subsequent versions of Windows.]"
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-ishungappwindow
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-iszoomed)\]
/// IsIconic
///
/// Determines whether a window is minimized.
///
/// ### Example
/// ```rust
/// # use hwnd::*;
/// # let hwnd = get_desktop_window(); // TODO: replace with an explicitly created unicode hwnd
/// let vscode = get_foreground_window(); // as if I'd have anything else focused
/// # if false {
/// assert!(is_iconic(vscode)); // as if I'd ever run vscode non-maximized
/// # }
///
/// assert!(!is_iconic(std::ptr::null_mut()));
/// assert!(!is_iconic(get_desktop_window()));
/// #
/// # assert!(!is_iconic(get_shell_window()));
/// # for p in 0 .. 8 * std::mem::size_of::<HWnd>() {
/// # let _ = is_iconic((1usize << p) as HWND); // shouldn't crash
/// # }
/// ```
// DO NOT DEFINE: IsProcessDPIAware
// "[IsProcessDPIAware is available for use in the operating systems specified in the Requirements section. It may be altered or unavailable in subsequent versions. Instead, use GetProcessDPIAwareness.]"
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-isprocessdpiaware
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-iswindow)\]
/// IsWindow
///
/// Determines whether the specified window handle identifies an existing window.
///
/// Valid uses of this function are few and far between - windows belonging to another thread
/// or process could be destroyed immediately after this returns true, and invalidated handles
/// might suddenly spring back to life as the handle value is reused.
///
/// ### Example
/// ```rust
/// # use hwnd::*;
/// # let valid_hwnd = get_desktop_window();
/// # let invalid_hwnd : HWND = !42 as HWND;
/// assert!( is_window( valid_hwnd));
/// assert!(!is_window(invalid_hwnd));
/// assert!(!is_window(std::ptr::null_mut()));
/// # for p in 0 .. 8 * std::mem::size_of::<HWnd>() {
/// # let _ = is_window((1usize << p) as HWND); // shouldn't crash
/// # }
/// ```
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-iswindow)\]
/// IsWindowUnicode
///
/// Determines whether the specified window is a native Unicode window.
///
/// ### Returns
/// * `true` if the window's class was registered with `RegisterClassW`
/// * `false` if the window's class was registered with `RegisterClassA`
/// * `false` if the window isn't valid, probably? (TryInto failed, HWnd null/dangling/destroyed, ...)
///
/// ### Example
/// ```rust
/// # use hwnd::*;
/// # let unicode_hwnd = get_desktop_window(); // TODO: replace with an explicitly created unicode hwnd
/// assert!( is_window_unicode(unicode_hwnd));
/// assert!(!is_window_unicode(std::ptr::null_mut()));
/// # for p in 0 .. 8 * std::mem::size_of::<HWnd>() {
/// # let _ = is_window_unicode((1usize << p) as HWND); // shouldn't crash
/// # }
/// ```
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-iswindow)\]
/// IsWindowVisible
///
/// Determines whether the specified window is [WS::VISIBLE].
/// May return `true` even if the window is totally obscured by other windows, clipped out-of-bounds, etc.
///
/// ### Example
/// ```rust
/// # use hwnd::*;
/// # let hwnd = get_desktop_window(); // TODO: replace with an explicitly created unicode hwnd
/// assert!( is_window_visible(hwnd));
/// assert!(!is_window_visible(std::ptr::null_mut()));
/// # for p in 0 .. 8 * std::mem::size_of::<HWnd>() {
/// # let _ = is_window_visible((1usize << p) as HWND); // shouldn't crash
/// # }
/// ```
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-iszoomed)\]
/// IsZoomed
///
/// Determines whether a window is maximized.
///
/// ### Example
/// ```rust
/// # use hwnd::*;
/// # let hwnd = get_desktop_window(); // TODO: replace with an explicitly created unicode hwnd
/// let vscode = get_foreground_window(); // as if I'd have anything else focused
/// # if false {
/// assert!(is_zoomed(vscode)); // as if I'd ever run vscode non-maximized
/// # }
///
/// assert!(!is_zoomed(std::ptr::null_mut()));
/// assert!(!is_zoomed(get_desktop_window()));
/// #
/// # assert!(!is_zoomed(get_shell_window()));
/// # for p in 0 .. 8 * std::mem::size_of::<HWnd>() {
/// # let _ = is_zoomed((1usize << p) as HWND); // shouldn't crash
/// # }
/// ```