Struct winsafe::gui::events::WindowEvents
source · pub struct WindowEvents(/* private fields */);
gui
only.Expand description
Exposes window messages.
You cannot directly instantiate this object, it is created internally by the window.
Implementations§
source§impl WindowEvents
impl WindowEvents
sourcepub fn wm<F>(&self, ident: WM, func: F)
pub fn wm<F>(&self, ident: WM, func: F)
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)
},
);
sourcepub fn wm_command<F>(
&self,
ctrl_id: impl Into<u16>,
code: impl Into<CMD>,
func: F
)
pub fn wm_command<F>( &self, ctrl_id: impl Into<u16>, code: impl Into<CMD>, func: F )
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)
},
);
sourcepub fn wm_notify<F>(
&self,
id_from: impl Into<u16>,
code: impl Into<NM>,
func: F
)
pub fn wm_notify<F>( &self, id_from: impl Into<u16>, code: impl Into<NM>, func: F )
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)
},
);
sourcepub fn wm_timer<F>(&self, timer_id: usize, func: F)
pub fn wm_timer<F>(&self, timer_id: usize, func: F)
WM_TIMER
message, narrowed to a specific timer ID.
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.
sourcepub fn wm_activate<F>(&self, func: F)
pub fn wm_activate<F>(&self, func: F)
WM_ACTIVATE
message.
sourcepub fn wm_activate_app<F>(&self, func: F)
pub fn wm_activate_app<F>(&self, func: F)
WM_ACTIVATEAPP
message.
sourcepub fn wm_app_command<F>(&self, func: F)
pub fn wm_app_command<F>(&self, func: F)
WM_APPCOMMAND
message.
sourcepub fn wm_cancel_mode<F>(&self, func: F)
pub fn wm_cancel_mode<F>(&self, func: F)
WM_CANCELMODE
message.
sourcepub fn wm_capture_changed<F>(&self, func: F)
pub fn wm_capture_changed<F>(&self, func: F)
WM_CAPTURECHANGED
message.
sourcepub fn wm_child_activate<F>(&self, func: F)
pub fn wm_child_activate<F>(&self, func: F)
WM_CHILDACTIVATE
message.
sourcepub fn wm_close<F>(&self, func: F)
pub fn wm_close<F>(&self, func: F)
WM_CLOSE
message.
§Default handling
If you handle this event, you’ll overwrite the default handling in:
- dialog
WindowMain
– callsDestroyWindow
; - dialog
WindowModal
– callsEndDialog
; - non-dialog
WindowModal
– re-enables parent and callsDestroyWindow
.
WM_CONTEXTMENU
message.
sourcepub fn wm_ctl_color_btn<F>(&self, func: F)
pub fn wm_ctl_color_btn<F>(&self, func: F)
WM_CTLCOLORBTN
message.
sourcepub fn wm_ctl_color_dlg<F>(&self, func: F)
pub fn wm_ctl_color_dlg<F>(&self, func: F)
WM_CTLCOLORDLG
message.
sourcepub fn wm_ctl_color_edit<F>(&self, func: F)
pub fn wm_ctl_color_edit<F>(&self, func: F)
WM_CTLCOLOREDIT
message.
sourcepub fn wm_ctl_color_list_box<F>(&self, func: F)
pub fn wm_ctl_color_list_box<F>(&self, func: F)
WM_CTLCOLORLISTBOX
message.
sourcepub fn wm_ctl_color_scroll_bar<F>(&self, func: F)
pub fn wm_ctl_color_scroll_bar<F>(&self, func: F)
WM_CTLCOLORSCROLLBAR
message.
sourcepub fn wm_ctl_color_static<F>(&self, func: F)
pub fn wm_ctl_color_static<F>(&self, func: F)
WM_CTLCOLORSTATIC
message.
sourcepub fn wm_create<F>(&self, func: F)
pub fn wm_create<F>(&self, func: F)
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)
},
);
sourcepub fn wm_dead_char<F>(&self, func: F)
pub fn wm_dead_char<F>(&self, func: F)
WM_DEADCHAR
message.
sourcepub fn wm_delete_item<F>(&self, func: F)
pub fn wm_delete_item<F>(&self, func: F)
WM_DELETEITEM
message.
sourcepub fn wm_destroy<F>(&self, func: F)
pub fn wm_destroy<F>(&self, func: F)
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(())
},
);
sourcepub fn wm_device_change<F>(&self, func: F)
pub fn wm_device_change<F>(&self, func: F)
WM_DEVICECHANGE
message.
sourcepub fn wm_display_change<F>(&self, func: F)
pub fn wm_display_change<F>(&self, func: F)
WM_DISPLAYCHANGE
message.
sourcepub fn wm_drop_files<F>(&self, func: F)
pub fn wm_drop_files<F>(&self, func: F)
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(())
},
);
sourcepub fn wm_end_session<F>(&self, func: F)
pub fn wm_end_session<F>(&self, func: F)
WM_ENDSESSION
message.
sourcepub fn wm_enter_idle<F>(&self, func: F)
pub fn wm_enter_idle<F>(&self, func: F)
WM_ENTERIDLE
message.
WM_ENTERMENULOOP
message.
sourcepub fn wm_enter_size_move<F>(&self, func: F)
pub fn wm_enter_size_move<F>(&self, func: F)
WM_ENTERSIZEMOVE
message.
sourcepub fn wm_erase_bkgnd<F>(&self, func: F)
pub fn wm_erase_bkgnd<F>(&self, func: F)
WM_ERASEBKGND
message.
WM_EXITMENULOOP
message.
sourcepub fn wm_exit_size_move<F>(&self, func: F)
pub fn wm_exit_size_move<F>(&self, func: F)
WM_EXITSIZEMOVE
message.
sourcepub fn wm_get_dlg_code<F>(&self, func: F)
pub fn wm_get_dlg_code<F>(&self, func: F)
WM_GETDLGCODE
message.
sourcepub fn wm_get_font<F>(&self, func: F)
pub fn wm_get_font<F>(&self, func: F)
WM_GETFONT
message.
WM_GETHMENU
message. Originally has MN
prefix.
sourcepub fn wm_get_min_max_info<F>(&self, func: F)
pub fn wm_get_min_max_info<F>(&self, func: F)
WM_GETMINMAXINFO
message.
sourcepub fn wm_get_text<F>(&self, func: F)
pub fn wm_get_text<F>(&self, func: F)
WM_GETTEXT
message.
sourcepub fn wm_get_text_length<F>(&self, func: F)
pub fn wm_get_text_length<F>(&self, func: F)
WM_GETTEXTLENGTH
message.
sourcepub fn wm_get_title_bar_info_ex<F>(&self, func: F)
pub fn wm_get_title_bar_info_ex<F>(&self, func: F)
WM_GETTITLEBARINFOEX
message.
sourcepub fn wm_h_scroll<F>(&self, func: F)
pub fn wm_h_scroll<F>(&self, func: F)
WM_HSCROLL
message.
sourcepub fn wm_init_dialog<F>(&self, func: F)
pub fn wm_init_dialog<F>(&self, func: F)
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)
},
);
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(())
},
);
sourcepub fn wm_key_down<F>(&self, func: F)
pub fn wm_key_down<F>(&self, func: F)
WM_KEYDOWN
message.
sourcepub fn wm_kill_focus<F>(&self, func: F)
pub fn wm_kill_focus<F>(&self, func: F)
WM_KILLFOCUS
message.
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(())
},
);
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(())
},
);
WM_LBUTTONUP
message.
WM_MBUTTONDBLCLK
message.
WM_MBUTTONDOWN
message.
WM_MBUTTONUP
message.
WM_MENUCOMMAND
message.
WM_MENUDRAG
message.
WM_MENURBUTTONUP
message.
sourcepub fn wm_mouse_hover<F>(&self, func: F)
pub fn wm_mouse_hover<F>(&self, func: F)
WM_MOUSEHOVER
message.
sourcepub fn wm_mouse_leave<F>(&self, func: F)
pub fn wm_mouse_leave<F>(&self, func: F)
WM_MOUSELEAVE
message.
sourcepub fn wm_mouse_move<F>(&self, func: F)
pub fn wm_mouse_move<F>(&self, func: F)
WM_MOUSEMOVE
message.
sourcepub fn wm_nc_calc_size<F>(&self, func: F)
pub fn wm_nc_calc_size<F>(&self, func: F)
WM_NCCALCSIZE
message.
sourcepub fn wm_nc_create<F>(&self, func: F)
pub fn wm_nc_create<F>(&self, func: F)
WM_NCCREATE
message.
sourcepub fn wm_nc_destroy<F>(&self, func: F)
pub fn wm_nc_destroy<F>(&self, func: F)
WM_NCDESTROY
message.
§Default handling
If you handle this event, you’ll overwrite the default handling in:
- non-dialog
WindowMain
; - dialog
WindowMain
.
In both cases, PostQuitMessage
is called.
sourcepub fn wm_nc_hit_test<F>(&self, func: F)
pub fn wm_nc_hit_test<F>(&self, func: F)
WM_NCHITTEST
message.
sourcepub fn wm_nc_paint<F>(&self, func: F)
pub fn wm_nc_paint<F>(&self, func: F)
WM_NCPAINT
message.
sourcepub fn wm_next_dlg_ctl<F>(&self, func: F)
pub fn wm_next_dlg_ctl<F>(&self, func: F)
WM_NEXTDLGCTL
message.
sourcepub fn wm_paint<F>(&self, func: F)
pub fn wm_paint<F>(&self, func: F)
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
},
);
sourcepub fn wm_parent_notify<F>(&self, func: F)
pub fn wm_parent_notify<F>(&self, func: F)
WM_PARENTNOTIFY
message.
sourcepub fn wm_power_broadcast<F>(&self, func: F)
pub fn wm_power_broadcast<F>(&self, func: F)
WM_POWERBROADCAST
message.
sourcepub fn wm_query_open<F>(&self, func: F)
pub fn wm_query_open<F>(&self, func: F)
WM_QUERYOPEN
message.
WM_RBUTTONDBLCLK
message.
WM_RBUTTONDOWN
message.
sourcepub fn wm_set_cursor<F>(&self, func: F)
pub fn wm_set_cursor<F>(&self, func: F)
WM_SETCURSOR
message.
sourcepub fn wm_set_focus<F>(&self, func: F)
pub fn wm_set_focus<F>(&self, func: F)
WM_SETFOCUS
message.
sourcepub fn wm_set_font<F>(&self, func: F)
pub fn wm_set_font<F>(&self, func: F)
WM_SETFONT
message.
sourcepub fn wm_set_icon<F>(&self, func: F)
pub fn wm_set_icon<F>(&self, func: F)
WM_SETICON
message.
sourcepub fn wm_set_redraw<F>(&self, func: F)
pub fn wm_set_redraw<F>(&self, func: F)
WM_SETREDRAW
message.
sourcepub fn wm_set_text<F>(&self, func: F)
pub fn wm_set_text<F>(&self, func: F)
WM_SETTEXT
message.
sourcepub fn wm_show_window<F>(&self, func: F)
pub fn wm_show_window<F>(&self, func: F)
WM_SHOWWINDOW
message.
sourcepub fn wm_style_changed<F>(&self, func: F)
pub fn wm_style_changed<F>(&self, func: F)
WM_STYLECHANGED
message.
sourcepub fn wm_style_changing<F>(&self, func: F)
pub fn wm_style_changing<F>(&self, func: F)
WM_STYLECHANGING
message.
sourcepub fn wm_sync_paint<F>(&self, func: F)
pub fn wm_sync_paint<F>(&self, func: F)
WM_SYNCPAINT
message.
sourcepub fn wm_sys_char<F>(&self, func: F)
pub fn wm_sys_char<F>(&self, func: F)
WM_SYSCHAR
message.
sourcepub fn wm_sys_command<F>(&self, func: F)
pub fn wm_sys_command<F>(&self, func: F)
WM_SYSCOMMAND
message.
sourcepub fn wm_sys_dead_char<F>(&self, func: F)
pub fn wm_sys_dead_char<F>(&self, func: F)
WM_SYSDEADCHAR
message.
sourcepub fn wm_sys_key_down<F>(&self, func: F)
pub fn wm_sys_key_down<F>(&self, func: F)
WM_SYSKEYDOWN
message.
sourcepub fn wm_sys_key_up<F>(&self, func: F)
pub fn wm_sys_key_up<F>(&self, func: F)
WM_SYSKEYUP
message.
sourcepub fn wm_theme_changed<F>(&self, func: F)
pub fn wm_theme_changed<F>(&self, func: F)
WM_THEMECHANGED
message.
WM_UNINITMENUPOPUP
message.
sourcepub fn wm_v_scroll<F>(&self, func: F)
pub fn wm_v_scroll<F>(&self, func: F)
WM_VSCROLL
message.
sourcepub fn wm_window_pos_changed<F>(&self, func: F)
pub fn wm_window_pos_changed<F>(&self, func: F)
WM_WINDOWPOSCHANGED
message.
sourcepub fn wm_window_pos_changing<F>(&self, func: F)
pub fn wm_window_pos_changing<F>(&self, func: F)
WM_WINDOWPOSCHANGING
message.
sourcepub fn wm_wts_session_change<F>(&self, func: F)
pub fn wm_wts_session_change<F>(&self, func: F)
WM_WTSSESSION_CHANGE
message.
WM_XBUTTONDBLCLK
message.
WM_XBUTTONDOWN
message.
WM_XBUTTONUP
message.