ergonomic_windows/
lib.rs

1//! # Ergonomic Windows
2//!
3//! Ergonomic wrappers around Windows APIs for Rust.
4//!
5//! This crate provides safe, idiomatic Rust interfaces to common Windows functionality:
6//!
7//! - **Error Handling**: Rich error types with Windows error code support
8//! - **Handle Management**: RAII wrappers for Windows handles
9//! - **String Utilities**: Easy conversion between Rust and Windows strings
10//! - **Process Management**: Create, manage, and query Windows processes
11//! - **File System**: Windows-specific file operations
12//! - **Registry**: Read and write Windows Registry keys
13//! - **Windows**: Create windows and handle messages
14//! - **Threading**: Threads, mutexes, events, semaphores
15//! - **Memory**: Virtual memory, heaps, memory info
16//! - **Console**: Console I/O, colors, cursor control
17//! - **Environment**: Environment variables
18//! - **Pipes**: Anonymous and named pipes for IPC
19//! - **Time**: High-resolution timers, system time
20//! - **Modules**: Dynamic library (DLL) loading
21//! - **System Info**: OS version, hardware info
22//! - **Security**: Tokens, privileges, elevation
23//! - **Controls**: Win32 common controls (buttons, edit, listbox, etc.)
24//! - **Direct2D**: Hardware-accelerated 2D graphics and text
25//! - **WebView2**: Chromium-based web browser control (requires feature)
26//! - **XAML**: WinRT XAML UI types and XAML Islands support
27//!
28//! ## Quick Start
29//!
30//! ```no_run
31//! use ergonomic_windows::process::Command;
32//! use ergonomic_windows::registry::{Key, RootKey, Access};
33//!
34//! // Spawn a process
35//! let process = Command::new("notepad.exe")
36//!     .arg("file.txt")
37//!     .spawn()?;
38//!
39//! // Read from the registry
40//! let key = Key::open(
41//!     RootKey::CURRENT_USER,
42//!     r"Software\Microsoft\Windows\CurrentVersion",
43//!     Access::READ,
44//! )?;
45//! let value = key.get_value("ProgramFilesDir")?;
46//!
47//! # Ok::<(), ergonomic_windows::error::Error>(())
48//! ```
49//!
50//! ## Feature Highlights
51//!
52//! ### RAII Handle Management
53//!
54//! Windows handles are automatically closed when dropped:
55//!
56//! ```ignore
57//! use ergonomic_windows::handle::OwnedHandle;
58//!
59//! {
60//!     let handle = OwnedHandle::new(some_raw_handle)?;
61//!     // Use the handle...
62//! } // Handle is automatically closed here
63//! # Ok::<(), ergonomic_windows::error::Error>(())
64//! ```
65//!
66//! ### Easy String Conversion
67//!
68//! Convert between Rust and Windows strings effortlessly:
69//!
70//! ```
71//! use ergonomic_windows::string::{to_wide, from_wide, WideString};
72//!
73//! // To wide string
74//! let wide = to_wide("Hello, Windows!");
75//!
76//! // From wide string
77//! let back = from_wide(&wide).unwrap();
78//!
79//! // For Windows APIs
80//! let ws = WideString::new("Hello");
81//! // use ws.as_pcwstr() with Windows APIs
82//! ```
83//!
84//! ### Process Management
85//!
86//! Create and manage processes with a fluent API:
87//!
88//! ```no_run
89//! use ergonomic_windows::process::Command;
90//!
91//! // Run a command and wait for completion
92//! let exit_code = Command::new("cmd.exe")
93//!     .args(["/c", "echo", "Hello"])
94//!     .no_window()
95//!     .run()?;
96//!
97//! # Ok::<(), ergonomic_windows::error::Error>(())
98//! ```
99//!
100//! ### Registry Access
101//!
102//! Read and write registry values with type safety:
103//!
104//! ```no_run
105//! use ergonomic_windows::registry::{Key, RootKey, Access, Value};
106//!
107//! // Write a value
108//! let key = Key::create(RootKey::CURRENT_USER, r"Software\MyApp", Access::ALL)?;
109//! key.set_value("Setting", &Value::dword(42))?;
110//!
111//! // Read it back
112//! let value = key.get_value("Setting")?;
113//! assert_eq!(value.as_dword(), Some(42));
114//!
115//! # Ok::<(), ergonomic_windows::error::Error>(())
116//! ```
117//!
118//! ### Threading and Synchronization
119//!
120//! ```no_run
121//! use ergonomic_windows::thread::{Thread, Mutex, Event};
122//! use std::sync::Arc;
123//!
124//! // Spawn a thread
125//! let thread = Thread::spawn(|| {
126//!     println!("Hello from thread!");
127//!     42
128//! })?;
129//! let exit_code = thread.join()?;
130//!
131//! // Use a mutex
132//! let mutex = Mutex::new(false)?;
133//! {
134//!     let _guard = mutex.lock()?;
135//!     // Protected region
136//! }
137//!
138//! // Use an event for signaling
139//! let event = Event::new_manual(false)?;
140//! event.set()?; // Signal
141//! event.wait()?; // Wait for signal
142//!
143//! # Ok::<(), ergonomic_windows::error::Error>(())
144//! ```
145//!
146//! ### System Information
147//!
148//! ```no_run
149//! use ergonomic_windows::sysinfo::{system_summary, OsVersion};
150//! use ergonomic_windows::security::is_elevated;
151//!
152//! let summary = system_summary()?;
153//! println!("OS: {}", summary.os_version);
154//! println!("CPUs: {}", summary.processor.processor_count);
155//! println!("Memory: {} MB", summary.memory.total_physical / 1024 / 1024);
156//! println!("Elevated: {}", is_elevated()?);
157//!
158//! # Ok::<(), ergonomic_windows::error::Error>(())
159//! ```
160
161#![cfg(windows)]
162#![warn(missing_docs)]
163
164// Core modules
165pub mod error;
166pub mod handle;
167pub mod string;
168
169// System modules
170pub mod console;
171pub mod env;
172pub mod fs;
173pub mod mem;
174pub mod module;
175pub mod pipe;
176pub mod process;
177pub mod registry;
178pub mod security;
179pub mod sysinfo;
180pub mod thread;
181pub mod time;
182pub mod window;
183
184// UI modules
185pub mod controls;
186pub mod d2d;
187pub mod webview;
188pub mod xaml;
189
190/// Prelude module for convenient imports.
191pub mod prelude {
192    pub use crate::error::{Error, Result, ResultExt};
193    pub use crate::fs::{exists, is_dir, is_file, FileAttributes, OpenOptions};
194    pub use crate::handle::{BorrowedHandle, HandleExt, OwnedHandle};
195    pub use crate::process::{Command, Process, ProcessAccess};
196    pub use crate::registry::{Access, Key, RootKey, Value};
197    pub use crate::string::{from_wide, from_wide_buffer, to_wide, WideString};
198    pub use crate::window::{
199        ExStyle, Message, MessageHandler, ShowCommand, Style, Window, WindowBuilder,
200    };
201
202    // System modules
203    pub use crate::console::{Color, Console, TextAttribute};
204    pub use crate::env::{expand as env_expand, get as env_get, set as env_set};
205    pub use crate::mem::{memory_status, MemoryStatus, Protection, VirtualMemory};
206    pub use crate::module::Library;
207    pub use crate::pipe::{AnonymousPipe, NamedPipeClient, NamedPipeServer};
208    pub use crate::security::{is_elevated, Token};
209    pub use crate::sysinfo::{system_summary, OsVersion, ProcessorInfo};
210    pub use crate::thread::{current_thread_id, sleep, Event, Mutex, Semaphore, Thread};
211    pub use crate::time::{tick_count, PerformanceCounter, Stopwatch, SystemTime};
212
213    // UI modules
214    pub use crate::controls::{
215        init_common_controls, Button, ButtonStyle, ComboBox, Control, Edit, EditStyle, Label,
216        ListBox, ProgressBar, ProgressStyle, TextAlign,
217    };
218    pub use crate::d2d::{
219        Color as D2DColor, D2DFactory, DWriteFactory, ParagraphAlignment, RenderTarget, SolidBrush,
220        TextAlignment, TextFormat,
221    };
222    pub use crate::webview::{WebView, WebViewBuilder};
223    pub use crate::xaml::{
224        CornerRadius, ElementTheme, FontStyle, FontWeight, GridLength, HorizontalAlignment,
225        Orientation, ScrollBarVisibility, TextTrimming, TextWrapping, Thickness, UiBuilder,
226        VerticalAlignment, Visibility, XamlColor, XamlHost,
227    };
228}