pub trait GuiEventsAll: GuiEvents {
    // Required methods
    fn wm_timer<F>(&self, timer_id: usize, func: F)
       where F: Fn() -> AnyResult<()> + 'static;
    fn wm_command<F>(&self, code: impl Into<CMD>, ctrl_id: u16, func: F)
       where F: Fn() -> AnyResult<()> + 'static;
    fn wm_notify<F>(&self, id_from: u16, code: impl Into<NM>, func: F)
       where F: Fn(Notify<'_>) -> AnyResult<Option<isize>> + 'static;

    // Provided methods
    fn wm_create<F>(&self, func: F)
       where F: Fn(Create<'_, '_, '_>) -> AnyResult<i32> + 'static { ... }
    fn wm_init_dialog<F>(&self, func: F)
       where F: Fn(InitDialog) -> AnyResult<bool> + 'static { ... }
    fn wm_command_accel_menu<F>(&self, ctrl_id: u16, func: F)
       where F: Fn() -> AnyResult<()> + 'static { ... }
}
Available on crate features kernel and gui only.
Expand description

Exposes methods to handle the basic window messages, plus timer and native control notifications.

Required Methods§

source

fn wm_timer<F>(&self, timer_id: usize, func: F)
where F: Fn() -> AnyResult<()> + 'static,

WM_TIMER message, narrowed to a specific timer ID.

source

fn wm_command<F>(&self, code: impl Into<CMD>, ctrl_id: u16, func: F)
where F: Fn() -> AnyResult<()> + 'static,

WM_COMMAND message, for specific code and control ID.

A command notification must be narrowed by the command code and the control ID, so the closure will be fired for that specific control at that specific event.

Note: Instead of using this event, you should always prefer the specific command notifications, which will give you the correct message parameters. This generic method should be used only when you have a custom, non-standard window notification.

use winsafe::{self as w, prelude::*, co, gui};

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

const ID_BTN: u16 = 1000;

wnd.on().wm_command(co::BN::CLICKED, ID_BTN,
    move || -> w::AnyResult<()> {
        println!("Button clicked!");
        Ok(())
    },
);
source

fn wm_notify<F>(&self, id_from: u16, code: impl Into<NM>, func: F)
where F: Fn(Notify<'_>) -> AnyResult<Option<isize>> + 'static,

WM_NOTIFY message, for specific ID and notification code.

Note: Instead of using this event, you should always prefer the specific notifications, which will give you the correct notification struct. This generic method should be used only when you have a custom, non-standard window notification.

Provided Methods§

source

fn wm_create<F>(&self, func: F)
where F: Fn(Create<'_, '_, '_>) -> AnyResult<i32> + 'static,

WM_CREATE message, sent only to non-dialog windows. Dialog windows receive WM_INITDIALOG instead.

§Examples
use winsafe::{self as w, prelude::*, gui, msg};

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

wnd.on().wm_create(
    move |p: msg::wm::Create| -> w::AnyResult<i32> {
        println!("Client area: {}x{}",
            p.createstruct.cx,
            p.createstruct.cy,
        );
        Ok(0)
    },
);
source

fn wm_init_dialog<F>(&self, func: F)
where F: Fn(InitDialog) -> AnyResult<bool> + 'static,

WM_INITDIALOG message, sent only to dialog windows. Non-dialog windows receive WM_CREATE instead.

Return true to set the focus to the first control in the dialog.

§Examples
use winsafe::{self as w, prelude::*, gui, msg};

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

wnd.on().wm_init_dialog(
    move |p: msg::wm::InitDialog| -> w::AnyResult<bool> {
        println!("Focused HWND: {}", p.hwnd_focus);
        Ok(true)
    },
);
source

fn wm_command_accel_menu<F>(&self, ctrl_id: u16, func: F)
where F: Fn() -> AnyResult<()> + 'static,

WM_COMMAND message, handling both CMD::Accelerator and CMD::Menu, for a specific command ID.

Ideal to be used with menu commands whose IDs are shared with accelerators.

Object Safety§

This trait is not object safe.

Implementors§