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
use crate::*;
use AsCStr;
use *;
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerwindowmessagea)\]
/// RegisterWindowMessageA
///
/// Defines a new window message that is guaranteed to be unique throughout the system.
/// The message value can be used when sending or posting messages.
///
/// Only use [register_window_message_a] when more than one application must process the same message.
/// For sending private messages within a window class, an application can use any integer in the range WM::USER through 0x7FFF.
///
/// ### Errors
/// * [ERROR::INVALID_PARAMETER] if `string` cannot be converted to a valid c string
/// * [ERROR::NOT_ENOUGH_MEMORY] if the system is unable to allocate a unique message constant between 0xC000 and 0xFFFF
///
/// ### Example
/// ```
/// # use hwnd::*;
/// # use winresult::*;
/// let wm1 = register_window_message_a(abistr::cstr!("WM_EXAMPLE")).unwrap();
/// let wm2 = register_window_message_a(abistr::cstr!("WM_EXAMPLE")).unwrap();
/// assert_eq!(wm1, wm2);
///
/// // ...leak tons of IDs...
/// # if !cfg!(nope) { return } // don't run the system out of atoms
/// # for i in 0xC000 .. 0xFFFF {
/// # let wm_name = format!("WM_EXAMPLE_{i}\0");
/// # let wm_name = abistr::CStrNonNull::from_units_with_nul(wm_name.as_bytes()).unwrap();
/// # let _ = register_window_message_a(wm_name);
/// # }
///
/// assert_eq!(ERROR::NOT_ENOUGH_MEMORY, register_window_message_a(abistr::cstr!("WM_EXAMPLE2")).unwrap_err());
/// ```
/// \[[learn.microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerwindowmessagew)\]
/// RegisterWindowMessageW
///
/// Defines a new window message that is guaranteed to be unique throughout the system.
/// The message value can be used when sending or posting messages.
///
/// Only use [register_window_message_w] when more than one application must process the same message.
/// For sending private messages within a window class, an application can use any integer in the range WM::USER through 0x7FFF.
///
/// ### Errors
/// * [ERROR::INVALID_PARAMETER] if `string` cannot be converted to a valid c string
/// * [ERROR::NOT_ENOUGH_MEMORY] if the system is unable to allocate a unique message constant between 0xC000 and 0xFFFF
///
/// ### Example
/// ```
/// # use hwnd::*;
/// # use winresult::*;
/// let wm1 = register_window_message_w(abistr::cstr16!("WM_EXAMPLE")).unwrap();
/// let wm2 = register_window_message_w(abistr::cstr16!("WM_EXAMPLE")).unwrap();
/// assert_eq!(wm1, wm2);
///
/// // ...leak tons of IDs...
/// # if !cfg!(nope) { return } // don't run the system out of atoms
/// # for i in 0xC000 .. 0xFFFF {
/// # let wm_name = format!("WM_EXAMPLE_{i}\0").encode_utf16().collect::<Vec<_>>();
/// # let wm_name = abistr::CStrNonNull::<u16>::from_units_with_nul(&wm_name).unwrap();
/// # let _ = register_window_message_w(wm_name);
/// # }
///
/// assert_eq!(ERROR::NOT_ENOUGH_MEMORY, register_window_message_w(abistr::cstr16!("WM_EXAMPLE2")).unwrap_err());
/// ```