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.
- Window
Builder - 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.renderis called whenever no messages are pending; returnOk(true)to keep rendering immediately (for continuous animation) orOk(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 ifrenderreturns an error.