Windows API Utils
A comprehensive Rust library providing utilities for Windows API programming, including coordinate conversion, bit manipulation, and Windows message handling with feature gating support.
Features
- Coordinate Conversion: Client-to-screen and screen-to-client coordinate transformation
- Bit Manipulation: Extract high/low words and bytes from integers (LOWORD, HIWORD, LOBYTE, HIBYTE)
- Message Handling: Type-safe WPARAM and LPARAM handling for Windows messages
- Cross-platform: Works on Windows, Linux, and macOS
- No-std Support: Core functionality available without standard library
- Feature Gating: Enable only the functionality you need
- Serialization: Optional serde support for message types
Feature Flags
coordinates: Enables coordinate conversion types and traitsbit-ops: Enables bit manipulation utilitiesmessages: Enables Windows message handlingserde: Enables serialization support for typesstd: Enables std support with thiserror (enabled by default)full: Enables all featuresminimal: Disables all optional features
Quick Start
Using Default Features (coordinates + messages)
[]
= "0.1"
use *;
// Coordinate conversion
let window = new;
let client_point = new;
let screen_point = window.client_to_screen.unwrap;
// Message handling
let message = mouse_move;
if let Some = parse_mouse_message
Using Only Coordinate Features
[]
= { = "0.1", = false, = ["coordinates"] }
use ;
let window = new;
let client_point = new;
let screen_point = window.client_to_screen.unwrap;
Using Only Bit Operations
[]
= { = "0.1", = false, = ["bit-ops"] }
use ;
let value = 0x12345678;
let low = loword; // 0x5678
let high = hiword; // 0x1234
let reconstructed = make_long;
Minimal Usage (no-std compatible)
[]
= { = "0.1", = false }
use WindowsUtilsError;
// Only error types available in minimal mode
API Overview
Coordinate Conversion
use ;
// Create a window with specific style
let style = WindowStyle ;
let window = new;
// Convert coordinates
let client_point = new;
let screen_point = window.client_to_screen?;
let back_to_client = window.screen_to_client?;
assert_eq!;
Bit Manipulation
use ;
// Basic bit operations
let value = 0x12345678;
assert_eq!;
assert_eq!;
assert_eq!;
// Byte operations
assert_eq!;
assert_eq!;
assert_eq!;
// Advanced bit manipulation
let bits = get_bits; // Extract bits 1-2: 0b01
let modified = set_bits; // Set bits 2-3: 0b1100
// LowHighWord utility
let lhw = new;
assert_eq!;
assert_eq!;
Message Handling
use ;
// Create mouse messages
let mouse_move = mouse_move;
let mouse_click = mouse_button;
// Parse messages
if let Some = parse_mouse_message
if let Some = parse_mouse_message
// Create and parse keyboard messages
let key_down = key_event;
if let Some = parse_key_message
Error Handling
The crate provides comprehensive error handling through the WindowsUtilsError enum:
use ;
match coordinate_operation
No-std Support
The crate supports no_std environments. When used without the std feature, error types use &'static str instead of String and don't depend on thiserror.
use WindowsUtilsError;
// Error types work in no_std environments
let error = InvalidCoordinates ;
Examples
Check out the examples in the examples directory:
coordinates_demo: Demonstrates coordinate conversionbit_ops_demo: Shows bit manipulation utilitiesmessages_demo: Illustrates Windows message handlingfull_demo: Comprehensive example using all features
Run examples with:
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Changelog
See CHANGELOG.md for version history and changes.
Documentation
Full API documentation is available at docs.rs.