winsafe\gui\windows/
window_message_only.rs

1use std::any::Any;
2use std::pin::Pin;
3use std::sync::Arc;
4
5use crate::co;
6use crate::decl::*;
7use crate::gui::{privs::*, *};
8use crate::prelude::*;
9use crate::user::privs::*;
10
11/// A
12/// [message-only](https://learn.microsoft.com/en-us/windows/win32/winmsg/window-features#message-only-windows)
13/// window, which can handle events.
14#[derive(Clone)]
15pub struct WindowMessageOnly(Pin<Arc<RawBase>>);
16
17unsafe impl Send for WindowMessageOnly {}
18
19impl AsRef<BaseWnd> for WindowMessageOnly {
20	fn as_ref(&self) -> &BaseWnd {
21		self.0.base()
22	}
23}
24
25impl GuiWindow for WindowMessageOnly {
26	fn hwnd(&self) -> &HWND {
27		self.0.base().hwnd()
28	}
29
30	fn as_any(&self) -> &dyn Any {
31		self
32	}
33}
34
35impl GuiParent for WindowMessageOnly {}
36
37impl WindowMessageOnly {
38	/// Instantiates a new `WindowMessageOnly` object, to be created internally
39	/// with [`HWND::CreateWindowEx`](crate::HWND::CreateWindowEx).
40	///
41	/// # Panics
42	///
43	/// Panics if the creation process fails.
44	#[must_use]
45	pub fn new(parent: Option<&WindowMessageOnly>) -> Self {
46		let new_self = Self(Arc::pin(RawBase::new()));
47		new_self.create(parent);
48		new_self
49	}
50
51	fn create(&self, parent: Option<&WindowMessageOnly>) {
52		let hinst = HINSTANCE::GetModuleHandle(None).expect(DONTFAIL);
53		let atom = self.0.register_class(
54			&hinst,
55			"",
56			co::CS::default(),
57			&Icon::None,
58			&Brush::None,
59			&Cursor::None,
60		);
61
62		let hparent_msg = unsafe { HWND::from_ptr(HWND_MESSAGE as _) };
63
64		self.0.create_window(
65			co::WS_EX::NoValue,
66			atom,
67			None,
68			co::WS::NoValue,
69			POINT::default(),
70			SIZE::default(),
71			Some(match parent {
72				Some(parent) => parent.hwnd(),
73				None => &hparent_msg, // special case: message-only window with no parent
74			}),
75			IdMenu::None,
76			&hinst,
77		);
78	}
79}