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
use crate::*;
use *;
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowthreadprocessid)\]
/// GetWindowThreadProcessId
///
/// Retrieves the identifier of the thread that created the specified window.
///
/// ### Returns
/// * Ok(thread_id)
/// * [ERROR::INVALID_WINDOW_HANDLE]
///
/// ### Example
/// ```rust
/// # use hwnd::*;
/// # use winresult::*;
/// # use std::ptr::*;
/// # let hwnd = get_desktop_window();
/// let thread = get_window_thread_id(hwnd).unwrap();
/// let hwnd_belongs_to_this_thread = thread == get_current_thread_id();
/// # assert!(!hwnd_belongs_to_this_thread, "desktop doesn't belong to us!");
/// #
/// # assert_eq!(ERROR::INVALID_WINDOW_HANDLE, get_window_thread_id(null_mut()).unwrap_err());
/// # for p in 0 .. 8 * std::mem::size_of::<HWnd>() {
/// # if let Err(e) = get_window_thread_id((1usize << p) as HWND) { // shouldn't crash
/// # assert_eq!(ERROR::INVALID_WINDOW_HANDLE, e);
/// # }
/// # }
/// ```
///
/// ### See Also
/// * [get_window_thread_process_id]
/// * [get_window_process_id]
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowthreadprocessid)\]
/// GetWindowThreadProcessId
///
/// Retrieves the identifier of the thread that created the specified window.
///
/// ### Returns
/// * Ok(thread_id)
/// * [ERROR::INVALID_WINDOW_HANDLE]
///
/// ### Example
/// ```rust
/// # use hwnd::*;
/// # use winresult::*;
/// # use std::ptr::*;
/// # let hwnd = get_desktop_window();
/// let process = get_window_process_id(hwnd).unwrap();
/// let hwnd_belongs_to_this_process = process == get_current_process_id();
/// # assert!(!hwnd_belongs_to_this_process, "desktop doesn't belong to us!");
/// #
/// # assert_eq!(ERROR::INVALID_WINDOW_HANDLE, get_window_process_id(null_mut()).unwrap_err());
/// # for p in 0 .. 8 * std::mem::size_of::<HWnd>() {
/// # if let Err(e) = get_window_process_id((1usize << p) as HWND) { // shouldn't crash
/// # assert_eq!(ERROR::INVALID_WINDOW_HANDLE, e);
/// # }
/// # }
/// ```
///
/// ### See Also
/// * [get_window_thread_id]
/// * [get_window_thread_process_id]
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowthreadprocessid)\]
/// GetWindowThreadProcessId
///
/// Retrieves the identifier of the thread that created the specified window and the identifier of the process that created the window.
///
/// ### Returns
/// * Ok((thread_id, process_id))
/// * [ERROR::INVALID_WINDOW_HANDLE]
///
/// ### Example
/// ```rust
/// # use hwnd::*;
/// # use winresult::*;
/// # use std::ptr::*;
/// # let hwnd = get_desktop_window();
/// let (thread, process) = get_window_thread_process_id(hwnd).unwrap();
/// let hwnd_belongs_to_this_thread = thread == get_current_thread_id();
/// # assert!(!hwnd_belongs_to_this_thread, "desktop doesn't belong to us!");
/// #
/// # assert_eq!(ERROR::INVALID_WINDOW_HANDLE, get_window_thread_process_id(null_mut()).unwrap_err());
/// # for p in 0 .. 8 * std::mem::size_of::<HWnd>() {
/// # if let Err(e) = get_window_thread_process_id((1usize << p) as HWND) { // shouldn't crash
/// # assert_eq!(ERROR::INVALID_WINDOW_HANDLE, e);
/// # }
/// # }
/// ```
///
/// ### See Also
/// * [get_window_process_id]
/// * [get_window_thread_id]
// TODO: test coverage with process/thread local windows