1use core::ffi::c_void;
2use core::num::NonZeroIsize;
3use core::ptr::NonNull;
4
5/// Raw display handle for Windows.
6///
7/// It can be used regardless of Windows window backend.
8#[non_exhaustive]
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10pub struct WindowsDisplayHandle {}
11
12impl WindowsDisplayHandle {
13 /// Create a new empty display handle.
14 ///
15 ///
16 /// # Example
17 ///
18 /// ```
19 /// # use raw_window_handle::WindowsDisplayHandle;
20 /// let handle = WindowsDisplayHandle::new();
21 /// ```
22 pub fn new() -> Self {
23 Self {}
24 }
25}
26
27/// Raw window handle for Win32.
28#[non_exhaustive]
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
30pub struct Win32WindowHandle {
31 /// A Win32 `HWND` handle.
32 pub hwnd: NonZeroIsize,
33 /// The `GWLP_HINSTANCE` associated with this type's `HWND`.
34 pub hinstance: Option<NonZeroIsize>,
35}
36
37impl Win32WindowHandle {
38 /// Create a new handle to a window.
39 ///
40 ///
41 /// # Example
42 ///
43 /// ```
44 /// # use core::num::NonZeroIsize;
45 /// # use raw_window_handle::Win32WindowHandle;
46 /// # struct HWND(isize);
47 /// #
48 /// let window: HWND;
49 /// # window = HWND(1);
50 /// let mut handle = Win32WindowHandle::new(NonZeroIsize::new(window.0).unwrap());
51 /// // Optionally set the GWLP_HINSTANCE.
52 /// # #[cfg(only_for_showcase)]
53 /// let hinstance = NonZeroIsize::new(unsafe { GetWindowLongPtrW(window, GWLP_HINSTANCE) }).unwrap();
54 /// # let hinstance = None;
55 /// handle.hinstance = hinstance;
56 /// ```
57 pub fn new(hwnd: NonZeroIsize) -> Self {
58 Self {
59 hwnd,
60 hinstance: None,
61 }
62 }
63}
64
65/// Raw window handle for WinRT.
66#[non_exhaustive]
67#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
68pub struct WinRtWindowHandle {
69 /// A WinRT `CoreWindow` handle.
70 pub core_window: NonNull<c_void>,
71}
72
73impl WinRtWindowHandle {
74 /// Create a new handle to a window.
75 ///
76 ///
77 /// # Example
78 ///
79 /// ```
80 /// # use core::ptr::NonNull;
81 /// # use raw_window_handle::WinRtWindowHandle;
82 /// # type CoreWindow = ();
83 /// #
84 /// let window: NonNull<CoreWindow>;
85 /// # window = NonNull::from(&());
86 /// let handle = WinRtWindowHandle::new(window.cast());
87 /// ```
88 pub fn new(core_window: NonNull<c_void>) -> Self {
89 Self { core_window }
90 }
91}
92