win64
Hand-crafted, idiomatic Rust wrappers for Win32
The idea for this library is to offer safer wrappers for the windows and windows-sys crates that offer low-level control while also helping to prevent invalid states.
use win64::prelude::*;
struct State;
impl WindowProcedure for State {
fn on_message(&mut self, window: &Window, message: &Message) -> Option<LResult> {
match message {
Message::Create(_) | Message::SettingChange(_) => {
window.dwm_set_window_attribute(DwmWindowAttribute::UseImmersiveDarkMode(is_os_dark_mode()));
}
Message::Destroy => {
window.quit();
}
Message::Paint => {
window.begin_paint(|hdc, ps| {
hdc.fill_rect(ps.paint, Brush::color_window());
});
}
_ => (),
}
None
}
}
fn main() -> Result<(), Error> {
let args = Args::get();
let class = WindowClass::builder()
.with_name("Window Class")
.register()?;
let hwnd = class
.create_window()
.with_procedure(State)
.with_name("Window")
.with_style(WindowStyle::OverlappedWindow | WindowStyle::Visible)
.with_size(Some(PhysicalSize::new(800, 500)))
.create()?;
MessageLoop::new().run();
Ok(())
}
[!WARNING]
While efforts are put in place to maintain compatibility, this crate is largely untested on versions of Windows older than Windows 11. Here be dragons.
Features
safe: This is a set of new API wrappers that aim to provide stronger checks against improper usage
rwh_05 / rwh_06: Implements the raw_window_handle traits on the window handle type.
Credits
- Some code (mostly utility functions and the keyboard events) taken from
winit under the Apache 2.0 license.
[!NOTE]
No AI-generated code.