#windowing #windows #api-bindings

win64

Hand-crafted, idiomatic Rust wrappers for Win32

18 releases

Uses new Rust 2024

new 0.0.18 Apr 8, 2026
0.0.17 Apr 8, 2026
0.0.13 Mar 29, 2026
0.0.4 Jul 7, 2025
0.0.1 Aug 10, 2024

#58 in Windows APIs


Used in 2 crates (via ventana-backend-win32)

MIT/Apache

160KB
4.5K SLoC

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> {
  // Fetch `winmain` args if you need them
  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()?;
  
  // Configure the thread message loop as you wish
  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.

Dependencies

~10–15MB
~243K SLoC