Struct WindowClass

Source
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 Windows 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>

Source

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.

Source

pub fn with_name<F>(name: &str, wnd_proc: F) -> Result<Self>
where F: WndProc + 'a,

Source

pub fn with_details<F>(wnd_class_ex: WNDCLASSEXW, wnd_proc: F) -> Result<Self>
where F: WndProc + 'a,

The lpfnWndProc field will be overwritten.

Source

pub fn make_name() -> Result<String>

Generates a time-based class name.

Source

pub fn atom(&self) -> u16

Trait Implementations§

Source§

impl Drop for WindowClass<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for WindowClass<'a>

§

impl<'a> !RefUnwindSafe for WindowClass<'a>

§

impl<'a> !Send for WindowClass<'a>

§

impl<'a> !Sync for WindowClass<'a>

§

impl<'a> Unpin for WindowClass<'a>

§

impl<'a> !UnwindSafe for WindowClass<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MapSelf for T

Source§

fn map_self<O, T>(self, op: O) -> T
where O: FnOnce(Self) -> T, Self: Sized,

Example: Read more
Source§

fn map_self_or_keep<O>(self, op: O) -> Self
where O: FnOnce(&Self) -> Option<Self>, Self: Sized,

Example: Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.