Struct winsafe::gui::events::WindowEvents[][src]

pub struct WindowEvents(_);
Expand description

Exposes window messages.

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

Implementations

Event to any window message.

Note: 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 when you have a custom, non-standard window message.

Examples

Handling a custom, user-defined message:

use winsafe::{co, gui, msg, BoxResult};

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

let CUSTOM_MSG = co::WM::from(0x1234);

wnd.on().wm(CUSTOM_MSG, {
    let wnd = wnd.clone(); // pass into the closure
    move |p: msg::WndMsg| -> BoxResult<isize> {
        println!("HWND: {}, msg ID: {}", wnd.hwnd(), p.msg_id);
        Ok(0)
    }
});

WM_TIMER message, narrowed to a specific timer ID.

Posted to the installing thread’s message queue when a timer expires.

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 when you have a custom, non-standard window notification.

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.

Examples

Closing the window on ESC key:

use winsafe::{co, gui, msg, BoxResult};

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

wnd.on().wm_command_accel_menu(co::DLGID::CANCEL.into(), {
    let wnd = wnd.clone(); // pass into the closure
    move || -> BoxResult<()> {
        wnd.hwnd().SendMessage(msg::wm::Close {});
        Ok(())
    }
});

WM_NOTIFY message, for specific ID and notification code.

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

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 when you have a custom, non-standard window notification.

WM_ACTIVATE message.

Sent to both the window being activated and the window being deactivated. If the windows use the same input queue, the message is sent synchronously, first to the window procedure of the top-level window being deactivated, then to the window procedure of the top-level window being activated. If the windows use different input queues, the message is sent asynchronously, so the window is activated immediately.

Default handling

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

WM_ACTIVATEAPP message.

Sent when a window belonging to a different application than the active window is about to be activated. The message is sent to the application whose window is being activated and to the application whose window is being deactivated.

WM_APPCOMMAND message.

Notifies a window that the user generated an application command event, for example, by clicking an application command button using the mouse or typing an application command key on the keyboard.

WM_CANCELMODE message.

Sent to cancel certain modes, such as mouse capture. For example, the system sends this message to the active window when a dialog box or message box is displayed. Certain functions also send this message explicitly to the specified window regardless of whether it is the active window. For example, the HWND::EnableWindow function sends this message when disabling the specified window.

WM_CAPTURECHANGED message.

Sent to the window that is losing the mouse capture.

WM_CHAR message.

Posted to the window with the keyboard focus when a WM_KEYDOWN message is translated by the TranslateMessage function. The WM_CHAR message contains the character code of the key that was pressed.

WM_CHILDACTIVATE message.

Sent to a child window when the user clicks the window’s title bar or when the window is activated, moved, or sized.

WM_CLOSE message.

Sent as a signal that a window or an application should terminate.

Default handling

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

WM_CONTEXTMENU message.

Notifies a window that the user desires a context menu to appear. The user may have clicked the right mouse button (right-clicked) in the window, pressed Shift+F10 or pressed the applications key (context menu key) available on some keyboards.

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

Sent when an application requests that a window be created by calling the HWND::CreateWindowEx function. The message is sent before the function returns. The window procedure of the new window receives this message after the window is created, but before the window becomes visible.

Examples

use winsafe::{gui, msg, BoxResult};

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

wnd.on().wm_create({
    let wnd = wnd.clone(); // pass into the closure
    move |p: msg::wm::Create| -> BoxResult<i32> {
        println!("HWND: {}, client area: {}x{}",
            wnd.hwnd(),
            p.createstruct.cx,
            p.createstruct.cy,
        );
        Ok(0)
    }
});

WM_CTLCOLORBTN message.

Sent to the parent window of a button before drawing the button. The parent window can change the button’s text and background colors. However, only owner-drawn buttons respond to the parent window processing this message.

WM_CTLCOLORDLG message.

Sent to a dialog box before the system draws the dialog box. By responding to this message, the dialog box can set its text and background colors using the specified display device context handle.

WM_CTLCOLOREDIT message.

An edit control that is not read-only or disabled sends the message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the edit control.

WM_CTLCOLORLISTBOX message.

Sent to the parent window of a list box before the system draws the list box. By responding to this message, the parent window can set the text and background colors of the list box by using the specified display device context handle.

WM_CTLCOLORSCROLLBAR message.

Sent to the parent window of a scroll bar control when the control is about to be drawn. By responding to this message, the parent window can use the display context handle to set the background color of the scroll bar control.

WM_CTLCOLORSTATIC message.

A static control, or an edit control that is read-only or disabled, sends the message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text foreground and background colors of the static control.

WM_DEADCHAR message.

Posted to the window with the keyboard focus when a WM_KEYUP message is translated by the TranslateMessage function. WM_DEADCHAR specifies a character code generated by a dead key. A dead key is a key that generates a character, such as the umlaut (double-dot), that is combined with another character to form a composite character. For example, the umlaut-O character (Ö) is generated by typing the dead key for the umlaut character, and then typing the O key.

WM_DELETEITEM message.

Sent to the owner of a list box or combo box when the list box or combo box is destroyed or when items are removed.

WM_DESTROY message.

Sent when a window is being destroyed. It is sent to the window procedure of the window being destroyed after the window is removed from the screen.

This message is sent first to the window being destroyed and then to the child windows (if any) as they are destroyed. During the processing of the message, it can be assumed that all child windows still exist.

Examples

use winsafe::{gui, BoxResult};

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

wnd.on().wm_destroy(|| -> BoxResult<()> {
    println!("Window is gone, goodbye!");
    Ok(())
});

WM_DISPLAYCHANGE message.

Sent to all windows when the display resolution has changed.

WM_DROPFILES message.

Sent when the user drops a file on the window of an application that has registered itself as a recipient of dropped files.

Examples

use winsafe::{gui, msg, BoxResult};

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

wnd.on().wm_drop_files(|p: msg::wm::DropFiles| -> BoxResult<()> {
    for dropped_file in p.hdrop.DragQueryFiles()?.iter() {
        println!("Dropped: {}", dropped_file);
    }
    Ok(())
});

WM_ENABLE message.

Sent when an application changes the enabled state of a window. It is sent to the window whose enabled state is changing. This message is sent before the HWND::EnableWindow function returns, but after the enabled state (WS::DISABLED style bit) of the window has changed.

WM_ENDSESSION message.

Sent to an application after the system processes the results of the WM_QUERYENDSESSION message. The WM_ENDSESSION message informs the application whether the session is ending.

WM_ENTERIDLE message.

Sent to the owner window of a modal dialog box or menu that is entering an idle state. A modal dialog box or menu enters an idle state when no messages are waiting in its queue after it has processed one or more previous messages.

WM_ENTERMENULOOP message.

Notifies an application’s main window procedure that a menu modal loop has been entered.

WM_ENTERSIZEMOVE message.

Sent one time to a window after it enters the moving or sizing modal loop. The window enters the moving or sizing modal loop when the user clicks the window’s title bar or sizing border, or when the window passes the WM_SYSCOMMAND message to the DefWindowProc function and the wParam parameter of the message specifies the SC_MOVE or SC_SIZE value. The operation is complete when DefWindowProc returns.

The system sends the message regardless of whether the dragging of full windows is enabled.

WM_ERASEBKGND message.

Sent when the window background must be erased (for example, when a window is resized). The message is sent to prepare an invalidated portion of a window for painting.

WM_EXITMENULOOP message.

Notifies an application’s main window procedure that a menu modal loop has been exited.

WM_EXITSIZEMOVE message.

Sent one time to a window, after it has exited the moving or sizing modal loop. The window enters the moving or sizing modal loop when the user clicks the window’s title bar or sizing border, or when the window passes the WM_SYSCOMMAND message to the DefWindowProc function and the wParam parameter of the message specifies the SC_MOVE or SC_SIZE value. The operation is complete when DefWindowProc returns.

WM_GETDLGCODE message.

By default, the system handles all keyboard input to the control; the system interprets certain types of keyboard input as dialog box navigation keys. To override this default behavior, the control can respond to the WM_GETDLGCODE message to indicate the types of input it wants to process itself.

WM_GETFONT message.

Retrieves the font with which the control is currently drawing its text.

MN_GETHMENU message.

Retrieves the menu handle for the current window.

WM_GETMINMAXINFO message.

Sent to a window when the size or position of the window is about to change. An application can use this message to override the window’s default maximized size and position, or its default minimum or maximum tracking size.

WM_GETTITLEBARINFOEX message.

Sent to request extended title bar information.

WM_HELP message.

Indicates that the user pressed the F1 key.

WM_HSCROLL message.

The WM_HSCROLL message is sent to a window when a scroll event occurs in the window’s standard horizontal scroll bar. This message is also sent to the owner of a horizontal scroll bar control when a scroll event occurs in the control.

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

Sent to the dialog box procedure immediately before a dialog box is displayed. Dialog box procedures typically use this message to initialize controls and carry out any other initialization tasks that affect the appearance of the dialog box.

Examples

use winsafe::{gui, msg, BoxResult};

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

wnd.on().wm_init_dialog({
    let wnd = wnd.clone(); // pass into the closure
    move |p: msg::wm::InitDialog| -> BoxResult<bool> {
        println!("Focused HWND: {}", p.hwnd_focus);
        Ok(true)
    }
});

WM_INITMENUPOPUP message.

Sent when a drop-down menu or submenu is about to become active. This allows an application to modify the menu before it is displayed, without changing the entire menu.

WM_KEYDOWN message.

Posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is pressed when the ALT key is not pressed.

WM_KEYUP message.

Posted to the window with the keyboard focus when a nonsystem key is released. A nonsystem key is a key that is pressed when the ALT key is not pressed, or a keyboard key that is pressed when a window has the keyboard focus.

WM_KILLFOCUS message.

Sent to a window immediately before it loses the keyboard focus.

WM_LBUTTONDBLCLK message.

Posted when the user double-clicks the left mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.

WM_LBUTTONDOWN message.

Posted when the user presses the left mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.

Examples

use winsafe::{gui, msg, BoxResult};

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

wnd.on().wm_l_button_down({
    let wnd = wnd.clone(); // pass into the closure
    move |p: msg::wm::LButtonDown| -> BoxResult<()> {
        println!("Point: {}x{}", p.coords.x, p.coords.y);
        Ok(())
    }
});

WM_LBUTTONUP message.

Posted when the user releases the left mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.

WM_MBUTTONDBLCLK message.

Posted when the user double-clicks the middle mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.

WM_MBUTTONDOWN message.

Posted when the user presses the middle mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.

WM_MBUTTONUP message.

Posted when the user releases the middle mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.

WM_MENUCOMMAND message.

Sent when the user makes a selection from a menu.

WM_MENUDRAG message.

Sent to the owner of a drag-and-drop menu when the user drags a menu item.

WM_MENURBUTTONUP message.

Sent when the user releases the right mouse button while the cursor is on a menu item.

WM_MOUSEHOVER message.

Posted to a window when the cursor hovers over the client area of the window for the period of time specified in a prior call to TrackMouseEvent.

WM_MOUSELEAVE message.

Posted to a window when the cursor leaves the client area of the window specified in a prior call to TrackMouseEvent.

WM_MOUSEMOVE message.

Posted to a window when the cursor moves. If the mouse is not captured, the message is posted to the window that contains the cursor. Otherwise, the message is posted to the window that has captured the mouse.

WM_MOVE message.

Sent after a window has been moved.

WM_MOVING message.

Sent to a window that the user is moving. By processing this message, an application can monitor the position of the drag rectangle and, if needed, change its position.

WM_NCCALCSIZE message.

Sent when the size and position of a window’s client area must be calculated. By processing this message, an application can control the content of the window’s client area when the size or position of the window changes.

WM_NCCREATE message.

Sent prior to the WM_CREATE message when a window is first created.

WM_NCDESTROY message.

Notifies a window that its nonclient area is being destroyed. The HWND::DestroyWindow function sends the message to the window following the WM_DESTROY message. WM_DESTROY is used to free the allocated memory object associated with the window.

The WM_NCDESTROY message is sent after the child windows have been destroyed. In contrast, WM_DESTROY is sent before the child windows are destroyed.

Default handling

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

WM_NCHITTEST message.

Sent to a window in order to determine what part of the window corresponds to a particular screen coordinate. This can happen, for example, when the cursor moves, when a mouse button is pressed or released, or in response to a call to a function such as HWND::WindowFromPoint. If the mouse is not captured, the message is sent to the window beneath the cursor. Otherwise, the message is sent to the window that has captured the mouse.

WM_NCPAINT message.

Sent to a window when its frame must be painted.

Default handling

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

WM_NEXTDLGCTL message.

Sent to a dialog box procedure to set the keyboard focus to a different control in the dialog box.

WM_NULL message.

Performs no operation. An application sends the message if it wants to post a message that the recipient window will ignore.

WM_PAINT message.

Sent when the system or another application makes a request to paint a portion of an application’s window. The message is sent when the HWND::UpdateWindow or HWND::RedrawWindow function is called, or by the DispatchMessage function when the application obtains a WM_PAINT message by using the GetMessage or PeekMessage function.

WM_PARENTNOTIFY message.

Sent to a window when a significant action occurs on a descendant window.

WM_QUERYOPEN message.

Sent to an icon when the user requests that the window be restored to its previous size and position.

WM_RBUTTONDBLCLK message.

Posted when the user double-clicks the right mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.

WM_RBUTTONDOWN message.

Posted when the user presses the right mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.

WM_RBUTTONUP message.

Posted when the user releases the right mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.

WM_SETCURSOR message.

Sent to a window if the mouse causes the cursor to move within a window and mouse input is not captured.

WM_SETFOCUS message.

Sent to a window after it has gained the keyboard focus.

Default handling

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

WM_SETFONT message.

Sets the font that a control is to use when drawing text.

WM_SETICON message.

Associates a new large or small icon with a window. The system displays the large icon in the Alt+TAB dialog box, and the small icon in the window caption.

WM_SETRDRAW message.

Sent to a window to allow changes in that window to be redrawn, or to prevent changes in that window from being redrawn.

WM_SHOWWINDOW message.

Sent to a window when the window is about to be hidden or shown.

WM_SIZE message.

Sent to a window after its size has changed.

Examples

use winsafe::{gui, msg, BoxResult};

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

wnd.on().wm_size({
    let wnd = wnd.clone(); // pass into the closure
    move |p: msg::wm::Size| -> BoxResult<()> {
        println!("HWND: {}, client area: {}x{}",
            wnd.hwnd(),
            p.width,
            p.height,
        );
        Ok(())
    }
});

WM_SIZING message.

Sent to a window that the user is resizing. By processing this message, an application can monitor the size and position of the drag rectangle and, if needed, change its size or position.

WM_STYLECHANGED message.

Sent to a window after the HWND::SetWindowLongPtr function has changed one or more of the window’s styles.

WM_STYLECHANGING message.

Sent to a window when the HWND::SetWindowLongPtr function is about to change one or more of the window’s styles.

WM_SYNCPAINT message.

Used to synchronize painting while avoiding linking independent GUI threads.

WM_SYSCHAR message.

Posted to the window with the keyboard focus when a WM_SYSKEYDOWN message is translated by the TranslateMessage function. It specifies the character code of a system character key that is, a character key that is pressed while the ALT key is down.

WM_SYSCOMMAND message.

A window receives this message when the user chooses a command from the Window menu (formerly known as the system or control menu) or when the user chooses the maximize button, minimize button, restore button, or close button.

WM_SYSDEADCHAR message.

Sent to the window with the keyboard focus when a WM_SYSKEYDOWN message is translated by the TranslateMessage function. WM_SYSDEADCHAR specifies the character code of a system dead key that is, a dead key that is pressed while holding down the ALT key.

WM_SYSKEYDOWN message.

Posted to the window with the keyboard focus when the user presses the F10 key (which activates the menu bar) or holds down the ALT key and then presses another key. It also occurs when no window currently has the keyboard focus; in this case, the WM_SYSKEYDOWN message is sent to the active window. The window that receives the message can distinguish between these two contexts by checking the context code in the lParam parameter.

WM_SYSKEYUP message.

Posted to the window with the keyboard focus when the user releases a key that was pressed while the ALT key was held down. It also occurs when no window currently has the keyboard focus; in this case, the WM_SYSKEYUP message is sent to the active window. The window that receives the message can distinguish between these two contexts by checking the context code in the lParam parameter.

WM_THEMECHANGED message.

Broadcast to every window following a theme change event. Examples of theme change events are the activation of a theme, the deactivation of a theme, or a transition from one theme to another.

WM_UNINITMENUPOPUP message.

Sent when a drop-down menu or submenu has been destroyed.

WM_VSCROLL message.

The WM_VSCROLL message is sent to a window when a scroll event occurs in the window’s standard vertical scroll bar. This message is also sent to the owner of a vertical scroll bar control when a scroll event occurs in the control.

WM_WINDOWPOSCHANGED message.

Sent to a window whose size, position, or place in the Z order has changed as a result of a call to the HWND::SetWindowPos function or another window-management function.

WM_WINDOWPOSCHANGING message.

Sent to a window whose size, position, or place in the Z order is about to change as a result of a call to the HWND::SetWindowPos function or another window-management function.

WM_XBUTTONDBLCLK message.

Posted when the user double-clicks the first or second X button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.

WM_XBUTTONDOWN message.

Posted when the user presses the first or second X button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.

WM_XBUTTONUP message.

Posted when the user releases the first or second X button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.