WinSafe
Windows API and GUI in safe, idiomatic Rust.
WinSafe has:
- low-level Win32 API constants, functions and structs;
- high-level structs to build native Win32 GUI applications.
If you're looking for a comprehensive Win32 coverage, take a look at winapi or windows crates, which are unsafe, but have everything.
WinSafe documentation:
Branch | Docs |
---|---|
Stable | docs.rs/winsafe |
Nightly (master) | rodrigocfd.github.io/winsafe/winsafe |
Current status
These are the estimated progresses of the GUI features:
GUI feature | Estimated progress |
---|---|
User window/dialogs (main, modal, modeless and control) | 100% |
Native controls | 85% |
Plus, below are the numbers of native FFI items implemented:
Native FFI item | Count |
---|---|
Functions | 682 |
Structs | 187 |
Constants | 12,833 |
Window messages | 648 |
Handles | 40 |
COM interfaces | 63 |
COM methods | 249 |
Usage
Add the dependency in your Cargo.toml
:
[]
= { = "0.0.16", = [] }
You can, alternatively, use the Nightly (master) branch directly, to get the latest features right away:
[]
= { = "https://github.com/rodrigocfd/winsafe", = [] }
Then you must enable the Cargo features you want to be included – these modules are named after native Windows DLL and library names, mostly.
The following Cargo features are available so far:
Feature | Description |
---|---|
comctl |
ComCtl32.dll, for Common Controls |
comdlg |
ComDlg32.dll, for the old Common Dialogs |
dshow |
DirectShow |
dxgi |
DirectX Graphics Infrastructure |
gdi |
Gdi32.dll, the Windows GDI |
gui |
The WinSafe high-level GUI abstractions |
kernel |
Kernel32.dll, Advapi32.dll and Ktmw32.dll – all others will include it |
msimg |
Msimg32.dll |
ole |
OLE and basic COM support |
oleaut |
OLE Automation |
shell |
Shell32.dll and Shlwapi.dll, the COM-based Windows Shell |
taskschd |
Task Scheduler |
user |
User32.dll, the basic Windows GUI support |
uxtheme |
UxTheme.dll, extended window theming |
version |
Version.dll, to manipulate *.exe version info |
Note that a Cargo feature may depend on other features, which will be enabled automatically.
Example
Note: You can find several examples in the dedicated repo: github.com/rodrigocfd/winsafe-examples
WinSafe allows you to create windows in two ways:
- programmatically defining parameters; or
- loading dialogs from a
.res
file created with a WYSIWYG resource editor.
The example below creates a window with a button programmatically. Note how the click event is handled with a closure:
[]
= { = "0.0.16", = ["gui"] }
use *;
use ;
License
Licensed under MIT license, see LICENSE.md for details.