FORGE KUI / learn

Open a native window in Rust

Start with the packaged EXE, then trace Platform, Window and Document.

Version 3.61.7

Lesson 14
Before you start
Windows x64, Rust SDK and the Rust MSVC toolchain
What you will build
Edit and build a Rust desktop window
Request the SDK →Rust SDK · Windows x64

Run before editing

Run the prebuilt program from the Rust SDK root. Confirm the native window and HTML heading, then open examples/hello_world.rs.

powershell
.\bin\kui_rust_hello_world.exe

Read the complete entry point

Platform::init prepares the runtime, Window::new creates the window, document.load_html sends HTML to KUI, and platform.run starts the event loop. This example uses no WebView or JavaScript runtime.

rust
use kui::{Platform, Window, WindowProps};

fn main() -> kui::Result<()> {
    let platform = Platform::init()?;
    let window = Window::new(&WindowProps {
        title: "KUI Rust SDK".into(),
        width: 960,
        height: 640,
        ..WindowProps::default()
    })?;
    let mut document = window.document()?;
    document.load_html(
        r#"<main style="padding:48px;font-family:sans-serif"><h1>Rust SDK 已接入 KUI</h1><p>此程序仅通过公开 C ABI 工作。</p></main>"#,
    )?;
    window.show()?;
    let _ = platform.run()?;
    Ok(())
}

Build this example only

Change the HTML heading. KUI_C_SDK points the build script to the import library; PATH lets the executable find native DLLs for this terminal session. Only this example is built.

powershell
$env:KUI_C_SDK = (Resolve-Path .\native).Path
$env:PATH = "$env:KUI_C_SDK\bin;$env:PATH"
cargo run --release --example hello_world

Check the result

Check the new heading. For linker errors, inspect native/lib/kui_c.lib; for launch errors, inspect native/bin and PATH. Keep UI objects on their creating thread and do not let panics cross the C ABI.