Crates.io | winctx |
lib.rs | winctx |
version | 0.0.19 |
source | src |
created_at | 2023-12-05 13:01:41.703733 |
updated_at | 2024-02-11 10:12:22.571583 |
description | A minimal window context for Rust on Windows. |
homepage | https://github.com/udoprog/winctx |
repository | https://github.com/udoprog/winctx |
max_upload_size | |
id | 1058600 |
size | 180,894 |
A minimal window context for Rust on Windows.
I read msdn so you don't have to.
This crate provides a minimalistic method for setting up and running a window. A window on windows is more like a generic application framework and doesn't actually need to have any visible elements, but is necessary to do many of the productive things you might want to do on Windows.
Some example of this are:
There are a few additional APIs provided by this crate because they are also useful:
This crate is an amalgamation and cleanup of code I've copied back and forth
between my projects, so it is fairly opinionated to things I personally find
useful. Not everything will be possible, but if there is something you're
missing and hate being happy enjoy Windows programming feel free to open
an issue or a pull request.
The primary purpose of this crate is to:
The basic loop looks like this:
use std::pin::pin;
use tokio::signal::ctrl_c;
use winctx::{Event, CreateWindow};
const ICON: &[u8] = include_bytes!("tokio.ico");
let mut window = CreateWindow::new("se.tedro.Example")
.window_name("Example Application");
let icon = window.icons().insert_buffer(ICON, 22, 22);
let area = window.new_area().icon(icon);
let menu = area.popup_menu();
let first = menu.push_entry("Example Application").id();
menu.push_separator();
let quit = menu.push_entry("Quit").id();
menu.set_default(first);
let (sender, mut event_loop) = window
.build()
.await?;
let mut ctrl_c = pin!(ctrl_c());
let mut shutdown = false;
loop {
let event = tokio::select! {
_ = ctrl_c.as_mut(), if !shutdown => {
sender.shutdown();
shutdown = true;
continue;
}
event = event_loop.tick() => {
event?
}
};
match event {
Event::MenuItemClicked { item_id, .. } => {
println!("Menu entry clicked: {item_id:?}");
if item_id == quit {
sender.shutdown();
}
}
Event::Shutdown { .. } => {
println!("Window shut down");
break;
}
_ => {}
}
}