Skip to main content

Crate windows_window

Crate windows_window 

Source
Expand description

§windows-window

The windows-window crate provides basic window creation and message-loop support for Canvas, WebView2, and custom rendering.

Start by adding the following to your Cargo.toml file:

[dependencies.windows-window]
version = "0.100"
use windows_window::*;

fn main() -> Result<()> {
    let window = Window::new("Hello")
        .size(800, 600)
        .on_resize(|width, height| {
            println!("resized to {width} x {height}");
        })
        .create()?;

    // `window.hwnd()` can be handed to windows-canvas, WebView2, Direct2D, etc.
    println!("created window {:?}", window.hwnd());

    run();
    Ok(())
}

Structs§

Window
A top-level window.
WindowBuilder
Builder for a Window.

Functions§

pump
Dispatches all currently-pending messages without blocking, then returns.
quit
Posts a quit message, causing the message loop to exit.
run
Runs a blocking, event-driven message loop until the window is closed.
run_with
Runs a message loop driven by render. render is called whenever no messages are pending; return Ok(true) to keep rendering immediately (for continuous animation) or Ok(false) to wait for the next message before rendering again (event-driven, e.g. when occluded or idle). Returns when the window is closed, or early if render returns an error.

Type Aliases§

Result
A specialized Result type that provides Windows error information.