Struct winsafe::gui::events::WindowEvents

source ·
pub struct WindowEvents(/* private fields */);
Available on crate feature gui only.
Expand description

Exposes window messages.

You cannot directly instantiate this object, it is created internally by the window.

Implementations§

source§

impl WindowEvents

source

pub fn wm<F>(&self, ident: WM, func: F)
where F: Fn(WndMsg) -> AnyResult<WmRet> + 'static,

Event to any window message.

Instead of using this event, you should always prefer the specific events, which will give you the correct message parameters. This generic method should be used only when you have a custom, non-standard window message – which should be pretty rare.

§Examples

Handling a custom, user-defined message:

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

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

let CUSTOM_MSG = unsafe { co::WM::from_raw(0x1234) };

wnd.on().wm(
    CUSTOM_MSG,
    move |p: msg::WndMsg| -> w::AnyResult<gui::WmRet> {
        println!("Msg ID: {}", p.msg_id);
        Ok(gui::WmRet::HandledOk)
    },
);
source

pub fn wm_command<F>( &self, ctrl_id: impl Into<u16>, code: impl Into<CMD>, func: F )
where F: Fn() -> AnyResult<WmRet> + '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.

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 CTRL_ID: u16 = 1010;

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

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

WM_NOTIFY message, for specific ID and notification code.

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.

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

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

const CTRL_ID: u16 = 1010;

wnd.on().wm_notify(
    CTRL_ID,
    co::NM::DBLCLK,
    move |_| -> w::AnyResult<gui::WmRet> {
        println!("Button clicked!");
        Ok(gui::WmRet::HandledOk)
    },
);
source

pub 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

pub fn wm_command_accel_menu<F>(&self, ctrl_id: impl Into<u16> + Copy, 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, like menu items.

source

pub fn wm_activate<F>(&self, func: F)
where F: Fn(Activate) -> AnyResult<()> + 'static,

WM_ACTIVATE message.

source

pub fn wm_activate_app<F>(&self, func: F)
where F: Fn(ActivateApp) -> AnyResult<()> + 'static,

WM_ACTIVATEAPP message.

source

pub fn wm_app_command<F>(&self, func: F)
where F: Fn(AppCommand) -> AnyResult<()> + 'static,

WM_APPCOMMAND message.

source

pub fn wm_cancel_mode<F>(&self, func: F)
where F: Fn() -> AnyResult<()> + 'static,

WM_CANCELMODE message.

source

pub fn wm_capture_changed<F>(&self, func: F)
where F: Fn(CaptureChanged) -> AnyResult<()> + 'static,

source

pub fn wm_char<F>(&self, func: F)
where F: Fn(Char) -> AnyResult<()> + 'static,

WM_CHAR message.

source

pub fn wm_child_activate<F>(&self, func: F)
where F: Fn() -> AnyResult<()> + 'static,

source

pub fn wm_close<F>(&self, func: F)
where F: Fn() -> AnyResult<()> + 'static,

WM_CLOSE message.

§Default handling

If you handle this event, you’ll overwrite the default handling in:

source

pub fn wm_context_menu<F>(&self, func: F)
where F: Fn() -> AnyResult<()> + 'static,

WM_CONTEXTMENU message.

source

pub fn wm_ctl_color_btn<F>(&self, func: F)
where F: Fn(CtlColorBtn) -> AnyResult<HBRUSH> + 'static,

WM_CTLCOLORBTN message.

source

pub fn wm_ctl_color_dlg<F>(&self, func: F)
where F: Fn(CtlColorDlg) -> AnyResult<HBRUSH> + 'static,

WM_CTLCOLORDLG message.

source

pub fn wm_ctl_color_edit<F>(&self, func: F)
where F: Fn(CtlColorEdit) -> AnyResult<HBRUSH> + 'static,

WM_CTLCOLOREDIT message.

source

pub fn wm_ctl_color_list_box<F>(&self, func: F)
where F: Fn(CtlColorListBox) -> AnyResult<HBRUSH> + 'static,

source

pub fn wm_ctl_color_scroll_bar<F>(&self, func: F)
where F: Fn(CtlColorScrollBar) -> AnyResult<HBRUSH> + 'static,

source

pub fn wm_ctl_color_static<F>(&self, func: F)
where F: Fn(CtlColorStatic) -> AnyResult<HBRUSH> + 'static,

source

pub 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

pub fn wm_dead_char<F>(&self, func: F)
where F: Fn(DeadChar) -> AnyResult<()> + 'static,

WM_DEADCHAR message.

source

pub fn wm_delete_item<F>(&self, func: F)
where F: Fn(DeleteItem<'_>) -> AnyResult<bool> + 'static,

WM_DELETEITEM message.

source

pub fn wm_destroy<F>(&self, func: F)
where F: Fn() -> AnyResult<()> + 'static,

WM_DESTROY message.

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

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

wnd.on().wm_destroy(
    move || -> w::AnyResult<()> {
        println!("Window is gone, goodbye!");
        Ok(())
    },
);
source

pub fn wm_device_change<F>(&self, func: F)
where F: Fn(DeviceChange<'_>) -> AnyResult<()> + 'static,

WM_DEVICECHANGE message.

source

pub fn wm_display_change<F>(&self, func: F)
where F: Fn(DisplayChange) -> AnyResult<()> + 'static,

source

pub fn wm_drop_files<F>(&self, func: F)
where F: Fn(DropFiles) -> AnyResult<()> + 'static,

WM_DROPFILES message.

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

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

wnd.on().wm_drop_files(
    move |mut p: msg::wm::DropFiles| -> w::AnyResult<()> {
        for dropped_file in p.hdrop.DragQueryFile()? {
            let dropped_file = dropped_file?;
            println!("Dropped: {}", dropped_file);
        }
        Ok(())
    },
);
source

pub fn wm_enable<F>(&self, func: F)
where F: Fn(Enable) -> AnyResult<()> + 'static,

WM_ENABLE message.

source

pub fn wm_end_session<F>(&self, func: F)
where F: Fn(EndSession) -> AnyResult<()> + 'static,

WM_ENDSESSION message.

source

pub fn wm_enter_idle<F>(&self, func: F)
where F: Fn(EnterIdle) -> AnyResult<()> + 'static,

WM_ENTERIDLE message.

source

pub fn wm_enter_menu_loop<F>(&self, func: F)
where F: Fn(EnterMenuLoop) -> AnyResult<()> + 'static,

source

pub fn wm_enter_size_move<F>(&self, func: F)
where F: Fn() -> AnyResult<()> + 'static,

source

pub fn wm_erase_bkgnd<F>(&self, func: F)
where F: Fn(EraseBkgnd) -> AnyResult<i32> + 'static,

WM_ERASEBKGND message.

source

pub fn wm_exit_menu_loop<F>(&self, func: F)
where F: Fn(ExitMenuLoop) -> AnyResult<()> + 'static,

WM_EXITMENULOOP message.

source

pub fn wm_exit_size_move<F>(&self, func: F)
where F: Fn() -> AnyResult<()> + 'static,

WM_EXITSIZEMOVE message.

source

pub fn wm_get_dlg_code<F>(&self, func: F)
where F: Fn(GetDlgCode<'_>) -> AnyResult<DLGC> + 'static,

WM_GETDLGCODE message.

source

pub fn wm_get_font<F>(&self, func: F)
where F: Fn() -> AnyResult<Option<HFONT>> + 'static,

WM_GETFONT message.

source

pub fn wm_get_hmenu<F>(&self, func: F)
where F: Fn() -> AnyResult<Option<HMENU>> + 'static,

WM_GETHMENU message. Originally has MN prefix.

source

pub fn wm_get_min_max_info<F>(&self, func: F)
where F: Fn(GetMinMaxInfo<'_>) -> AnyResult<()> + 'static,

source

pub fn wm_get_text<F>(&self, func: F)
where F: Fn(GetText<'_>) -> AnyResult<u32> + 'static,

WM_GETTEXT message.

source

pub fn wm_get_text_length<F>(&self, func: F)
where F: Fn() -> AnyResult<u32> + 'static,

source

pub fn wm_get_title_bar_info_ex<F>(&self, func: F)
where F: Fn(GetTitleBarInfoEx<'_>) -> AnyResult<()> + 'static,

source

pub fn wm_h_scroll<F>(&self, func: F)
where F: Fn(HScroll) -> AnyResult<()> + 'static,

WM_HSCROLL message.

source

pub fn wm_help<F>(&self, func: F)
where F: Fn(Help<'_>) -> AnyResult<()> + 'static,

WM_HELP message.

source

pub 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

pub fn wm_init_menu_popup<F>(&self, func: F)
where F: Fn(InitMenuPopup) -> AnyResult<()> + 'static,

WM_INITMENUPOPUP message.

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

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

wnd.on().wm_init_menu_popup(
    move |p: msg::wm::InitMenuPopup| -> w::AnyResult<()> {
        if p.hmenu.GetMenuItemID(0).unwrap() == 3001 { // check ID of 1st item
            p.hmenu.EnableMenuItem(w::IdPos::Id(3001), false)?;
        }
        Ok(())
    },
);
source

pub fn wm_key_down<F>(&self, func: F)
where F: Fn(KeyDown) -> AnyResult<()> + 'static,

WM_KEYDOWN message.

source

pub fn wm_key_up<F>(&self, func: F)
where F: Fn(KeyUp) -> AnyResult<()> + 'static,

WM_KEYUP message.

source

pub fn wm_kill_focus<F>(&self, func: F)
where F: Fn(KillFocus) -> AnyResult<()> + 'static,

WM_KILLFOCUS message.

source

pub fn wm_l_button_dbl_clk<F>(&self, func: F)
where F: Fn(LButtonDblClk) -> AnyResult<()> + 'static,

WM_LBUTTONDBLCLK message.

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

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

wnd.on().wm_l_button_dbl_clk(
    move |p: msg::wm::LButtonDblClk| -> w::AnyResult<()> {
        println!("Point: {}x{}", p.coords.x, p.coords.y);
        Ok(())
    },
);
source

pub fn wm_l_button_down<F>(&self, func: F)
where F: Fn(LButtonDown) -> AnyResult<()> + 'static,

WM_LBUTTONDOWN message.

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

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

wnd.on().wm_l_button_down(
    move |p: msg::wm::LButtonDown| -> w::AnyResult<()> {
        println!("Point: {}x{}", p.coords.x, p.coords.y);
        Ok(())
    },
);
source

pub fn wm_l_button_up<F>(&self, func: F)
where F: Fn(LButtonUp) -> AnyResult<()> + 'static,

WM_LBUTTONUP message.

source

pub fn wm_m_button_dbl_clk<F>(&self, func: F)
where F: Fn(MButtonDblClk) -> AnyResult<()> + 'static,

source

pub fn wm_m_button_down<F>(&self, func: F)
where F: Fn(MButtonDown) -> AnyResult<()> + 'static,

WM_MBUTTONDOWN message.

source

pub fn wm_m_button_up<F>(&self, func: F)
where F: Fn(MButtonUp) -> AnyResult<()> + 'static,

WM_MBUTTONUP message.

source

pub fn wm_menu_command<F>(&self, func: F)
where F: Fn(MenuCommand) -> AnyResult<()> + 'static,

WM_MENUCOMMAND message.

source

pub fn wm_menu_drag<F>(&self, func: F)
where F: Fn(MenuDrag) -> AnyResult<MND> + 'static,

WM_MENUDRAG message.

source

pub fn wm_menu_r_button_up<F>(&self, func: F)
where F: Fn(MenuRButtonUp) -> AnyResult<()> + 'static,

source

pub fn wm_mouse_hover<F>(&self, func: F)
where F: Fn(MouseHover) -> AnyResult<()> + 'static,

WM_MOUSEHOVER message.

source

pub fn wm_mouse_leave<F>(&self, func: F)
where F: Fn() -> AnyResult<()> + 'static,

WM_MOUSELEAVE message.

source

pub fn wm_mouse_move<F>(&self, func: F)
where F: Fn(MouseMove) -> AnyResult<()> + 'static,

WM_MOUSEMOVE message.

source

pub fn wm_move<F>(&self, func: F)
where F: Fn(Move) -> AnyResult<()> + 'static,

WM_MOVE message.

source

pub fn wm_moving<F>(&self, func: F)
where F: Fn(Moving<'_>) -> AnyResult<()> + 'static,

WM_MOVING message.

source

pub fn wm_nc_calc_size<F>(&self, func: F)
where F: Fn(NcCalcSize<'_, '_>) -> AnyResult<WVR> + 'static,

WM_NCCALCSIZE message.

source

pub fn wm_nc_create<F>(&self, func: F)
where F: Fn(NcCreate<'_, '_, '_>) -> AnyResult<bool> + 'static,

WM_NCCREATE message.

source

pub fn wm_nc_destroy<F>(&self, func: F)
where F: Fn() -> AnyResult<()> + 'static,

WM_NCDESTROY message.

§Default handling

If you handle this event, you’ll overwrite the default handling in:

In both cases, PostQuitMessage is called.

source

pub fn wm_nc_hit_test<F>(&self, func: F)
where F: Fn(NcHitTest) -> AnyResult<HT> + 'static,

WM_NCHITTEST message.

source

pub fn wm_nc_paint<F>(&self, func: F)
where F: Fn(NcPaint) -> AnyResult<()> + 'static,

WM_NCPAINT message.

source

pub fn wm_next_dlg_ctl<F>(&self, func: F)
where F: Fn(NextDlgCtl) -> AnyResult<()> + 'static,

WM_NEXTDLGCTL message.

source

pub fn wm_null<F>(&self, func: F)
where F: Fn() -> AnyResult<()> + 'static,

WM_NULL message.

source

pub fn wm_paint<F>(&self, func: F)
where F: Fn() -> AnyResult<()> + 'static,

WM_PAINT message.

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

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

let wnd2 = wnd.clone(); // to pass into the closure

wnd.on().wm_paint(
    move || -> w::AnyResult<()> {
        let hdc = wnd2.hwnd().BeginPaint()?;

        // hdc painting...

        Ok(())

        // EndPaint() automatically called
    },
);
source

pub fn wm_parent_notify<F>(&self, func: F)
where F: Fn(ParentNotify) -> AnyResult<()> + 'static,

WM_PARENTNOTIFY message.

source

pub fn wm_power_broadcast<F>(&self, func: F)
where F: Fn(PowerBroadcast<'_>) -> AnyResult<()> + 'static,

source

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

WM_QUERYOPEN message.

source

pub fn wm_r_button_dbl_clk<F>(&self, func: F)
where F: Fn(RButtonDblClk) -> AnyResult<()> + 'static,

source

pub fn wm_r_button_down<F>(&self, func: F)
where F: Fn(RButtonDown) -> AnyResult<()> + 'static,

WM_RBUTTONDOWN message.

source

pub fn wm_r_button_up<F>(&self, func: F)
where F: Fn(RButtonUp) -> AnyResult<()> + 'static,

source

pub fn wm_set_cursor<F>(&self, func: F)
where F: Fn(SetCursor) -> AnyResult<bool> + 'static,

WM_SETCURSOR message.

source

pub fn wm_set_focus<F>(&self, func: F)
where F: Fn(SetFocus) -> AnyResult<()> + 'static,

WM_SETFOCUS message.

source

pub fn wm_set_font<F>(&self, func: F)
where F: Fn(SetFont) -> AnyResult<()> + 'static,

WM_SETFONT message.

source

pub fn wm_set_icon<F>(&self, func: F)
where F: Fn(SetIcon) -> AnyResult<Option<HICON>> + 'static,

WM_SETICON message.

source

pub fn wm_set_redraw<F>(&self, func: F)
where F: Fn(SetRedraw) -> AnyResult<()> + 'static,

WM_SETREDRAW message.

source

pub fn wm_set_text<F>(&self, func: F)
where F: Fn(SetText) -> AnyResult<bool> + 'static,

WM_SETTEXT message.

source

pub fn wm_show_window<F>(&self, func: F)
where F: Fn(ShowWindow) -> AnyResult<()> + 'static,

WM_SHOWWINDOW message.

source

pub fn wm_size<F>(&self, func: F)
where F: Fn(Size) -> AnyResult<()> + 'static,

WM_SIZE message.

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

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

wnd.on().wm_size(
    move |p: msg::wm::Size| -> w::AnyResult<()> {
        println!("Client area: {}x{}",
            p.client_area.cx,
            p.client_area.cy,
        );
        Ok(())
    },
);
source

pub fn wm_sizing<F>(&self, func: F)
where F: Fn(Sizing<'_>) -> AnyResult<()> + 'static,

WM_SIZING message.

source

pub fn wm_style_changed<F>(&self, func: F)
where F: Fn(StyleChanged<'_>) -> AnyResult<()> + 'static,

WM_STYLECHANGED message.

source

pub fn wm_style_changing<F>(&self, func: F)
where F: Fn(StyleChanging<'_>) -> AnyResult<()> + 'static,

source

pub fn wm_sync_paint<F>(&self, func: F)
where F: Fn() -> AnyResult<()> + 'static,

WM_SYNCPAINT message.

source

pub fn wm_sys_char<F>(&self, func: F)
where F: Fn(SysChar) -> AnyResult<()> + 'static,

WM_SYSCHAR message.

source

pub fn wm_sys_command<F>(&self, func: F)
where F: Fn(SysCommand) -> AnyResult<()> + 'static,

WM_SYSCOMMAND message.

source

pub fn wm_sys_dead_char<F>(&self, func: F)
where F: Fn(SysDeadChar) -> AnyResult<()> + 'static,

WM_SYSDEADCHAR message.

source

pub fn wm_sys_key_down<F>(&self, func: F)
where F: Fn(SysKeyDown) -> AnyResult<()> + 'static,

WM_SYSKEYDOWN message.

source

pub fn wm_sys_key_up<F>(&self, func: F)
where F: Fn(SysKeyUp) -> AnyResult<()> + 'static,

WM_SYSKEYUP message.

source

pub fn wm_theme_changed<F>(&self, func: F)
where F: Fn() -> AnyResult<()> + 'static,

WM_THEMECHANGED message.

source

pub fn wm_uninit_menu_popup<F>(&self, func: F)
where F: Fn(UninitMenuPopup) -> AnyResult<()> + 'static,

source

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

WM_UNDO message.

source

pub fn wm_v_scroll<F>(&self, func: F)
where F: Fn(VScroll) -> AnyResult<()> + 'static,

WM_VSCROLL message.

source

pub fn wm_window_pos_changed<F>(&self, func: F)
where F: Fn(WindowPosChanged<'_>) -> AnyResult<()> + 'static,

source

pub fn wm_window_pos_changing<F>(&self, func: F)
where F: Fn(WindowPosChanging<'_>) -> AnyResult<()> + 'static,

source

pub fn wm_wts_session_change<F>(&self, func: F)
where F: Fn(WtsSessionChange) -> AnyResult<()> + 'static,

source

pub fn wm_x_button_dbl_clk<F>(&self, func: F)
where F: Fn(XButtonDblClk) -> AnyResult<()> + 'static,

source

pub fn wm_x_button_down<F>(&self, func: F)
where F: Fn(XButtonDown) -> AnyResult<()> + 'static,

WM_XBUTTONDOWN message.

source

pub fn wm_x_button_up<F>(&self, func: F)
where F: Fn(XButtonUp) -> AnyResult<()> + 'static,

WM_XBUTTONUP message.

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.