pub struct WindowClass<'a> { /* private fields */ }
Expand description
A window class registered with RegisterClassExW()
, containing a window procedure closure. Necessary for creating windows.
- Don’t drop it before any
Window
s created with it, because this tries to unregister the class (struct field order is relevant). - Don’t use
Get...
/SetWindowLongPtrW(...GWLP_USERDATA...)
on a window created from an instance of this struct, because it stores internal data necessary for the struct to function.
Implementations§
Source§impl<'a> WindowClass<'a>
impl<'a> WindowClass<'a>
Sourcepub fn new<F>(wnd_proc: F) -> Result<Self>where
F: WndProc + 'a,
pub fn new<F>(wnd_proc: F) -> Result<Self>where
F: WndProc + 'a,
Creates a new class with a name from Self::make_name()
.
Pass the window procedure of the class that you implement. Its parameters are:
- Without types:
hwnd, msg_id, wparam, lparam
- With types:
hwnd: HWND, msg_id: u32, wparam: WPARAM, lparam: LPARAM
Return None
from the procedure to cause DefWindowProcW()
being called and its return value being used. You sometimes should also call it yourself when handling certain messages and returning Some(...)
.
Note that some functions like, e.g., DestroyWindow()
and MoveWindow()
synchronously cause the window procedure to be called again during their calls. This means that closing over an Rc<RefCell<...>>
and calling borrow_mut()
to call your actual procedure implementation (can be a method with self parameter) will cause a borrowing panic. Using Rc<ReentrantRefCell<...>>
instead solves this. See crate::ReentrantRefCell
for more information.
pub fn with_name<F>(name: &str, wnd_proc: F) -> Result<Self>where
F: WndProc + 'a,
Sourcepub fn with_details<F>(wnd_class_ex: WNDCLASSEXW, wnd_proc: F) -> Result<Self>where
F: WndProc + 'a,
pub fn with_details<F>(wnd_class_ex: WNDCLASSEXW, wnd_proc: F) -> Result<Self>where
F: WndProc + 'a,
The lpfnWndProc
field will be overwritten.