makepad/libs/windows/windows-rs
Kevin Boos 6c8ba38ec4
Windows: treat a click activation (WA_CLICKACTIVE) as gaining focus (#1293)
`WM_ACTIVATE` only sent `WindowGotFocus` for `WA_ACTIVE`, so clicking an inactive window
to bring it forward sent `WindowLostFocus` instead, leaving it unfocused until the next
Alt-Tab. Anything other than `WA_INACTIVE` now counts as activation.
`WA_INACTIVE` replaces the now-unused `WA_ACTIVE` in the bindgen filter and vendored bindings.
2026-10-07 06:49:17 +02:00
..
src Windows: treat a click activation (WA_CLICKACTIVE) as gaining focus (#1293) 2026-10-07 06:49:17 +02:00
Cargo.toml tools, arch, docs, workspace, examples, sqlite, wasm_bridge 2026-09-15 13:40:33 +02:00
license-apache-2.0 windowsrs vendored 2026-02-14 12:27:38 +01:00
license-mit windowsrs vendored 2026-02-14 12:27:38 +01:00
readme.md windowsrs vendored 2026-02-14 12:27:38 +01:00
rustfmt.toml windowsrs vendored 2026-02-14 12:27:38 +01:00

Rust for Windows

The windows and windows-sys crates let you call any Windows API past, present, and future using code generated on the fly directly from the metadata describing the API and right into your Rust package where you can call them as if they were just another Rust module. The Rust language projection follows in the tradition established by C++/WinRT of building language projections for Windows using standard languages and compilers, providing a natural and idiomatic way for Rust developers to call Windows APIs.

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

[dependencies.windows]
version = ">=0.59, <=0.62"
features = [
    "Data_Xml_Dom",
    "Win32_Security",
    "Win32_System_Threading",
    "Win32_UI_WindowsAndMessaging",
]

Using a range instead of the default Caret requirements helps avoid duplicate versions in downstream graphs and improves resolver flexibility.

Make use of any Windows APIs as needed:

use windows::{
    core::*, Data::Xml::Dom::*, Win32::Foundation::*, Win32::System::Threading::*,
    Win32::UI::WindowsAndMessaging::*,
};

fn main() -> Result<()> {
    let doc = XmlDocument::new()?;
    doc.LoadXml(h!("<html>hello world</html>"))?;

    let root = doc.DocumentElement()?;
    assert!(root.NodeName()? == "html");
    assert!(root.InnerText()? == "hello world");

    unsafe {
        let event = CreateEventW(None, true, false, None)?;
        SetEvent(event)?;
        WaitForSingleObject(event, 0);
        CloseHandle(event)?;

        MessageBoxA(None, s!("Ansi"), s!("Caption"), MB_OK);
        MessageBoxW(None, w!("Wide"), w!("Caption"), MB_OK);
    }

    Ok(())
}