Windows API Utilities
A comprehensive utility library for Windows API programming in Rust, providing type-safe abstractions for coordinate conversion, bit operations, and message parameter handling with full windows crate compatibility.
Features
- 🎯 Coordinate Conversion: Client-to-screen and screen-to-client coordinate transformations
- 🔧 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
- 🔄 Windows Interop: Seamless compatibility with the
windowscrate - 🌐 Cross-platform: Works on Windows, Linux, and macOS (no Windows API calls)
- 📦 No-std Support: Core functionality available without std
- 🎛️ Feature Gating: Enable only the functionality you need
- 📊 Serialization: Optional serde support for message types
Quick Start
Using Default Features
[]
= "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
With Windows Crate Interop
[]
= { = "0.1", = ["windows-interop"] }
= "0.52"
use *;
use ;
// Seamless conversion - zero cost!
let win_wparam = WPARAM;
let our_wparam = from;
let back_to_win: WPARAM = our_wparam.into;
assert_eq!;
// Full message conversion
let win_msg = MSG ;
let our_msg: WindowMessage = win_msg.into;
Coordinate Features Only
[]
= { = "0.1", = false, = ["coordinates"] }
use ;
let window = new;
let client_point = new;
let screen_point = window.client_to_screen.unwrap;
Bit Operations Only
[]
= { = "0.1", = false, = ["bit-ops"] }
use ;
let value = 0x12345678;
let low = loword; // 0x5678
let high = hiword; // 0x1234
let reconstructed = make_long;
// Advanced bit manipulation
let bits = get_bits; // 0b01
let modified = set_bit; // 0b1011
Minimal Usage (no-std compatible)
[]
= { = "0.1", = false }
use WindowsUtilsError;
// Only error types available in minimal mode
Feature Flags
coordinates- Coordinate conversion types and traitsbit-ops- Bit manipulation utilities (LOWORD, HIWORD, etc.)messages- Windows message handling (WPARAM, LPARAM)serde- Serialization support for typeswindows-interop- Seamless compatibility withwindowscratestd- Standard library support withthiserrorfull- All features enabledminimal- No optional features (default: enabled)
Examples
Coordinate Conversion
use *;
// Create a window with specific style
let style = WindowStyle ;
let window_rect = new;
let window = new;
// Convert client coordinates to screen coordinates
let client_coords = new;
let screen_coords = window.client_to_screen.unwrap;
println!;
// Convert screen coordinates back to client coordinates
let converted_back = window.screen_to_client.unwrap;
assert_eq!;
Bit Operations
use *;
// Extract words from 32-bit value
let value = 0x12345678;
let low_word = loword; // 0x5678
let high_word = hiword; // 0x1234
// Reconstruct value
let reconstructed = make_long;
assert_eq!;
// Use the LowHighWord struct for more functionality
let lhw = new;
assert_eq!;
assert_eq!;
assert_eq!;
// Advanced bit manipulation
let value = 0b10101010;
let extracted = get_bits; // 0b101
let with_bit_set = set_bit; // 0b10101011
let is_bit_set = is_bit_set; // true
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 keyboard messages
let key_down = key_event;
Windows Crate Integration
use *;
use UIWindowsAndMessaging;
// Convert from windows crate message
// Direct type compatibility
No-std Support
The crate supports no_std environments. When used without the std feature, only core functionality is available:
use WindowsUtilsError;
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.