Trait winsafe::prelude::GuiWindow

source ·
pub trait GuiWindow: Send {
    // Required methods
    fn hwnd(&self) -> &HWND;
    fn as_any(&self) -> &dyn Any;
}
Available on crate features kernel and gui only.
Expand description

Any window. Exposes the underlying window handle.

Prefer importing this trait through the prelude:

use winsafe::prelude::*;

Required Methods§

source

fn hwnd(&self) -> &HWND

Returns the underlying handle for this control.

Note that the handle is initially null, receiving an actual value only after the control is physically created, what usually happens right before WM_CREATE or WM_INITDIALOG events.

source

fn as_any(&self) -> &dyn Any

Converts a reference to the Any trait. This is useful when storing a collection of polymorphic controls, because Any allows downcasting.

§Examples
use std::sync::Arc;
use winsafe::{self as w, prelude::*, gui};

let parent: gui::WindowMain; // initialized somewhere

let ctrls: Vec<Arc<dyn GuiNativeControl>> = vec![
    Arc::new( gui::Edit::new(&parent, gui::EditOpts::default()) ),
    Arc::new( gui::Button::new(&parent, gui::ButtonOpts::default()) ),
];

let edit = ctrls[0].as_any() // retrieve 1st element, which is an Edit
    .downcast_ref::<gui::Edit>()
    .expect("This Edit downcast should never fail.");

edit.set_text("Foo");

Implementors§