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
use crate::*;
use *;
use *;
use c_char;
use *;
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowtextlengtha)\]
/// GetWindowTextLengthA
///
/// Retrieves the length, in characters, of the specified window's title bar text (if the window has a title bar).
/// If the specified window is a control, the function retrieves the length of the text within the control.
/// The docs claim [get_window_text_length_a] cannot retrieve the length of the text of an edit control in another application.
/// However, testing reveals it works fine on at least the desktop window.
///
/// ### Errors
/// * [ERROR::INVALID_WINDOW_HANDLE] If `hwnd` is invalid
///
/// ### Example
/// ```
/// # use hwnd::*;
/// # use winresult::*;
/// # use std::ptr::*;
/// let hwnd = unsafe { create_window_ex_a(0, abistr::cstr!("Message"), abistr::cstr!("Title"), 0, 0, 0, 0, 0, HWnd::MESSAGE, null_mut(), None, null_mut()) }.unwrap();
/// assert_eq!(Ok(5), get_window_text_length_a(hwnd));
/// assert_eq!(Ok(0), get_window_text_length_a(get_desktop_window()));
/// assert_eq!(ERROR::INVALID_WINDOW_HANDLE, get_window_text_length_a(!42usize as HWND));
/// ```
///
/// ### See Also
/// * [get_window_text_a]
/// * [get_window_text_length_w]
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowtextlengthW)\]
/// GetWindowTextLengthW
///
/// Retrieves the length, in characters, of the specified window's title bar text (if the window has a title bar).
/// If the specified window is a control, the function retrieves the length of the text within the control.
/// The docs claim [get_window_text_length_w] cannot retrieve the length of the text of an edit control in another application.
/// However, testing reveals it works fine on at least the desktop window.
///
/// ### Errors
/// * [ERROR::INVALID_WINDOW_HANDLE] If `hwnd` is invalid
///
/// ### Example
/// ```
/// # use hwnd::*;
/// # use winresult::*;
/// # use std::ptr::*;
/// let hwnd = unsafe { create_window_ex_w(0, abistr::cstr16!("Message"), abistr::cstr16!("Title"), 0, 0, 0, 0, 0, HWnd::MESSAGE, null_mut(), None, null_mut()) }.unwrap();
/// assert_eq!(Ok(5), get_window_text_length_w(hwnd));
/// assert_eq!(Ok(0), get_window_text_length_w(get_desktop_window()));
/// assert_eq!(ERROR::INVALID_WINDOW_HANDLE, get_window_text_length_w(!42usize as HWND));
/// ```
///
/// ### See Also
/// * [get_window_text_w]
/// * [get_window_text_length_a]
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowtexta)\]
/// GetWindowTextA
///
/// Copies the text of the specified window's title bar (if it has one) into a buffer.
/// If the specified window is a control, the text of the control is copied.
/// The docs claim [get_window_text_a] cannot retrieve the text of a control in another application.
/// However, testing reveals it works fine on at least the desktop window.
///
/// ### Errors
/// * ~~[ERROR::INVALID_WINDOW_HANDLE] If `hwnd` is invalid... *sometimes*.~~
/// * May succeed with 0 length despite `hwnd` being invalid!
///
/// ### Example
/// ```
/// # use hwnd::*;
/// # use abistr::*;
/// # use winresult::*;
/// # use std::os::raw::c_char;
/// # use std::ptr::*;
/// let hwnd = unsafe { create_window_ex_a(0, abistr::cstr!("Message"), abistr::cstr!("Title"), 0, 0, 0, 0, 0, HWnd::MESSAGE, null_mut(), None, null_mut()) }.unwrap();
/// let mut title = [0; 1024];
/// let title = get_window_text_a(hwnd, &mut title).unwrap();
/// assert_eq!(b"Title", bytemuck::cast_slice::<c_char, u8>(title));
/// #
/// # assert!(get_window_text_a(get_desktop_window(), title).unwrap().is_empty());
/// # assert!(get_window_text_a(!42usize as HWND, title).unwrap().is_empty());
/// ```
///
/// ### See Also
/// * [get_window_text_w]
/// * [get_window_text_os]
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowtextw)\]
/// GetWindowTextW
///
/// Copies the text of the specified window's title bar (if it has one) into a buffer.
/// If the specified window is a control, the text of the control is copied.
/// The docs claim [get_window_text_w] cannot retrieve the text of a control in another application.
/// However, testing reveals it works fine on at least the desktop window.
///
/// ### Errors
/// * ~~[ERROR::INVALID_WINDOW_HANDLE] If `hwnd` is invalid... *sometimes*.~~
/// * May succeed with 0 length despite `hwnd` being invalid!
///
/// ### Example
/// ```
/// # use hwnd::*;
/// # use abistr::*;
/// # use winresult::*;
/// # use std::ptr::*;
/// let hwnd = unsafe { create_window_ex_w(0, abistr::cstr16!("Message"), abistr::cstr16!("Title"), 0, 0, 0, 0, 0, HWnd::MESSAGE, null_mut(), None, null_mut()) }.unwrap();
/// let mut title = [0u16; 1024];
/// let title = get_window_text_w(hwnd, &mut title).unwrap();
/// assert_eq!(abistr::cstr16!("Title").to_units(), title);
/// #
/// # assert!(get_window_text_w(get_desktop_window(), title).unwrap().is_empty());
/// # assert!(get_window_text_w(!42usize as HWND, title).unwrap().is_empty());
/// ```
///
/// ### See Also
/// * [get_window_text_a]
/// * [get_window_text_os]
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowtextw)\]
/// GetWindowTextW
///
/// Copies the text of the specified window's title bar (if it has one) into a buffer.
/// If the specified window is a control, the text of the control is copied.
/// The docs claim [get_window_text_os] cannot retrieve the text of a control in another application.
/// However, testing reveals it works fine on at least the desktop window.
///
/// ### Errors
/// * [ERROR::INVALID_WINDOW_HANDLE] If `hwnd` is invalid
///
/// ### Example
/// ```
/// # use hwnd::*;
/// # use abistr::*;
/// # use winresult::*;
/// # use std::ptr::*;
/// let hwnd = unsafe { create_window_ex_w(0, abistr::cstr16!("Message"), abistr::cstr16!("Title"), 0, 0, 0, 0, 0, HWnd::MESSAGE, null_mut(), None, null_mut()) }.unwrap();
/// let mut title = [0u16; 1024];
/// let title = get_window_text_os(hwnd).unwrap();
/// assert_eq!("Title", title.to_string_lossy());
///
/// let title = get_window_text_os(get_desktop_window()).unwrap();
/// assert_eq!("", title.to_string_lossy());
/// #
/// # assert_eq!(ERROR::INVALID_WINDOW_HANDLE, get_window_text_os(!42usize as HWND));
/// ```
///
/// ### See Also
/// * [get_window_text_a]
/// * [get_window_text_w]