{"id":13611747,"url":"https://github.com/rodrigocfd/winsafe","last_synced_at":"2025-04-14T13:46:46.598Z","repository":{"id":37334244,"uuid":"218154384","full_name":"rodrigocfd/winsafe","owner":"rodrigocfd","description":"Windows API and GUI in safe, idiomatic Rust.","archived":false,"fork":false,"pushed_at":"2024-04-22T01:06:45.000Z","size":270344,"stargazers_count":439,"open_issues_count":3,"forks_count":26,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-04-22T13:19:02.669Z","etag":null,"topics":["directx","ffi","gui","native","rust","win32","windows"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/winsafe","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rodrigocfd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-10-28T22:09:08.000Z","updated_at":"2024-04-23T20:55:55.888Z","dependencies_parsed_at":"2023-02-17T09:46:37.335Z","dependency_job_id":"62d6a4a0-b5ad-413f-9a6f-8d190a332c88","html_url":"https://github.com/rodrigocfd/winsafe","commit_stats":{"total_commits":1097,"total_committers":7,"mean_commits":"156.71428571428572","dds":0.008204193254329972,"last_synced_commit":"32eadb3ec448fe48e77a35f38b8daec6cb78e4df"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigocfd%2Fwinsafe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigocfd%2Fwinsafe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigocfd%2Fwinsafe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigocfd%2Fwinsafe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rodrigocfd","download_url":"https://codeload.github.com/rodrigocfd/winsafe/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248890621,"owners_count":21178472,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["directx","ffi","gui","native","rust","win32","windows"],"created_at":"2024-08-01T19:02:04.155Z","updated_at":"2025-04-14T13:46:46.556Z","avatar_url":"https://github.com/rodrigocfd.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# WinSafe\r\n\r\n[![Crates.io](https://img.shields.io/crates/v/winsafe.svg?style=flat-square)](https://crates.io/crates/winsafe)\r\n[![Crates.io total downloads](https://img.shields.io/crates/d/winsafe?color=seagreen\u0026style=flat-square)](https://crates.io/crates/winsafe)\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?label=license\u0026style=flat-square)](https://opensource.org/licenses/MIT)\r\n[![Lines of code](https://tokei.rs/b1/github/rodrigocfd/winsafe?label=LoC\u0026style=flat-square)](https://github.com/rodrigocfd/winsafe)\r\n\r\nWindows API and GUI in safe, idiomatic Rust.\r\n\r\nWinSafe has:\r\n\r\n* low-level Win32 API constants, functions and structs;\r\n* high-level structs to build native Win32 GUI applications.\r\n\r\nWinSafe documentation:\r\n\r\n| Branch | Docs |\r\n| - | - |\r\n| Stable | [docs.rs/winsafe](https://docs.rs/winsafe) |\r\n| Nightly (master) | [rodrigocfd.github.io/winsafe/winsafe](https://rodrigocfd.github.io/winsafe/winsafe/) |\r\n\r\n## Current status\r\n\r\n### Native FFI items implemented\r\n\r\n| Native FFI item | Count |\r\n| - | -: |\r\n| Functions | 822 |\r\n| Structs | 247 |\r\n| Constants | 13,539 |\r\n| Window messages | 655 |\r\n| Handles | 50 |\r\n| COM interfaces | 90 |\r\n| COM methods | 559 |\r\n\r\nAlthough WinSafe already has a lot of Win32 APIs, it doesn't have *everything*, simply because Win32 API is gigantic. So if you're looking for a comprehensive Win32 coverage, take a look at [winapi](https://crates.io/crates/winapi) or [windows](https://crates.io/crates/windows) crates, which are *unsafe*, but have everything.\r\n\r\n### High-level GUI controls implemented\r\n\r\n* User custom window/dialog – main, modal, modeless, control, message-only.\r\n* Native controls – button, check box, combo box, date and time picker, edit, header, label, list box, list view, month calendar, progress bar, radio button, status bar, tab, track bar, tree view, up down.\r\n\r\n## Usage\r\n\r\nAdd the dependency in your `Cargo.toml`:\r\n\r\n```toml\r\n[dependencies]\r\nwinsafe = { version = \"0.0.23\", features = [] }\r\n```\r\n\r\nThen you must enable the [Cargo features](https://doc.rust-lang.org/cargo/reference/features.html#the-features-section) you want to be included – these modules are named after native Windows DLL and library names, mostly.\r\n\r\n### Cargo features\r\n\r\nThe APIs in WinSafe are split into Cargo features to speed up compilation time. Only the features you include will be compiled.\r\n\r\nThe following Cargo features are available so far:\r\n\r\n| Feature | Description |\r\n| - | - |\r\n| `advapi` | Advapi32.dll and Ktmw32.dll, advanced kernel functions |\r\n| `comctl` | ComCtl32.dll, the [Common Controls](https://learn.microsoft.com/en-us/windows/win32/api/_controls/) |\r\n| `dshow` | [DirectShow](https://learn.microsoft.com/en-us/windows/win32/directshow/directshow) |\r\n| `dwm` | [Desktop Window Manager](https://learn.microsoft.com/en-us/windows/win32/dwm/dwm-overview) |\r\n| `dxgi` | [DirectX Graphics Infrastructure](https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/dx-graphics-dxgi) |\r\n| `gdi` | Gdi32.dll, the [Windows GDI](https://learn.microsoft.com/en-us/windows/win32/gdi/windows-gdi) |\r\n| **`gui`** | **The WinSafe high-level GUI abstractions** |\r\n| `kernel` | Kernel32.dll, basic kernel functions |\r\n| `mf` | [Media Foundation](https://learn.microsoft.com/en-us/windows/win32/medfound/microsoft-media-foundation-sdk) |\r\n| `ole` | Basic OLE/COM support |\r\n| `oleaut` | [OLE Automation](https://learn.microsoft.com/en-us/windows/win32/api/_automat/) |\r\n| `psapi` | [Process Status API](https://learn.microsoft.com/en-us/windows/win32/api/_psapi/) |\r\n| **`raw-dylib`** | **Enables [raw-dylib](https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute) linking** |\r\n| `shell` | Shell32.dll, Shlwapi.dll, and Userenv.dll, the COM-based [Windows Shell](https://learn.microsoft.com/en-us/windows/win32/shell/shell-entry) |\r\n| `taskschd` | [Task Scheduler](https://learn.microsoft.com/en-us/windows/win32/taskschd/task-scheduler-start-page) |\r\n| `user` | User32.dll and ComDlg32.dll, the basic Windows GUI support |\r\n| `uxtheme` | UxTheme.dll, extended window theming |\r\n| `version` | Version.dll, to manipulate *.exe version info |\r\n| `winspool` | [Print Spooler API](https://learn.microsoft.com/en-us/windows/win32/printdocs/print-spooler-api) |\r\n\r\nDon't worry about including dependency features. Once you use a feature, Cargo will add and resolve all dependencies automatically.\r\n\r\nYou can visualize the complete dependency graph [here](https://github.com/rodrigocfd/winsafe/blob/master/features-chart.md).\r\n\r\n## Example\r\n\r\n**Note:** You can find several examples in the dedicated repo: [github.com/rodrigocfd/winsafe-examples](https://github.com/rodrigocfd/winsafe-examples)\r\n\r\nWinSafe allows you to create windows in two ways:\r\n\r\n* programmatically defining parameters; or\r\n* [loading dialogs](https://github.com/rodrigocfd/winsafe-examples/tree/master/03_dialog_resources) from a `.res` file created with a WYSIWYG resource editor.\r\n\r\nThe [example below](https://github.com/rodrigocfd/winsafe-examples/tree/master/01_button_click/) creates a window  with a button programmatically. Note how the click event is handled with a closure:\r\n\r\n![Example 01](https://raw.githubusercontent.com/rodrigocfd/winsafe-examples/master/01_button_click/screen.gif)\r\n\r\n```toml\r\n[dependencies]\r\nwinsafe = { version = \"0.0.23\", features = [\"gui\"] }\r\n```\r\n\r\n```rust\r\n#![windows_subsystem = \"windows\"]\r\n\r\nuse winsafe::{self as w, prelude::*, gui};\r\n\r\nfn main() {\r\n    let my = MyWindow::new(); // instantiate our main window\r\n    if let Err(e) = my.wnd.run_main(None) { // ... and run it\r\n        eprintln!(\"{}\", e);\r\n    }\r\n}\r\n\r\n\r\n#[derive(Clone)]\r\npub struct MyWindow {\r\n    wnd:       gui::WindowMain, // responsible for managing the window\r\n    btn_hello: gui::Button,     // a button\r\n}\r\n\r\nimpl MyWindow {\r\n    pub fn new() -\u003e Self {\r\n        let wnd = gui::WindowMain::new( // instantiate the window manager\r\n            gui::WindowMainOpts {\r\n                title: \"My window title\".to_owned(),\r\n                size: gui::dpi(300, 150),\r\n                ..Default::default() // leave all other options as default\r\n            },\r\n        );\r\n\r\n        let btn_hello = gui::Button::new(\r\n            \u0026wnd, // the window manager is the parent of our button\r\n            gui::ButtonOpts {\r\n                text: \"\u0026Click me\".to_owned(),\r\n                position: gui::dpi(20, 20),\r\n                ..Default::default()\r\n            },\r\n        );\r\n\r\n        let new_self = Self { wnd, btn_hello };\r\n        new_self.events(); // attach our events\r\n        new_self\r\n    }\r\n\r\n    fn events(\u0026self) {\r\n        let wnd = self.wnd.clone(); // clone so it can be passed into the closure\r\n        self.btn_hello.on().bn_clicked(move || {\r\n            wnd.hwnd().SetWindowText(\"Hello, world!\")?; // call native Windows API\r\n            Ok(())\r\n        });\r\n    }\r\n}\r\n```\r\n\r\n## License\r\n\r\nLicensed under [MIT license](https://opensource.org/licenses/MIT), see [LICENSE.md](LICENSE.md) for details.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigocfd%2Fwinsafe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frodrigocfd%2Fwinsafe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigocfd%2Fwinsafe/lists"}