Expand description
Windows API utilities for coordinate conversion, bit operations, and message parameter handling.
This crate provides utilities for working with Windows API concepts including:
- Coordinate conversion between client and screen coordinates
- Bit manipulation (LOWORD, HIWORD, LOBYTE, HIBYTE)
- Windows message parameter handling (WPARAM, LPARAM)
§Features
- Coordinate Conversion: ClientToScreen, ScreenToClient functionality
- Bit Manipulation: Extract high/low words and bytes from integers
- Message Parameters: Type-safe WPARAM and LPARAM handling
- Cross-platform: Works on Windows, Linux, and macOS
- No-std support: Core functionality available without std
- Feature Gating: Enable only the functionality you need
- Serialization: Optional serde support for message types
- Windows Interop: Seamless compatibility with windows crate
§Feature Flags
coordinates: Enables coordinate conversion types and traitsbit-ops: Enables bit manipulation utilitiesmessages: Enables Windows message handlingserde: Enables serialization support for typeswindows-interop: Enables seamless compatibility with windows cratefull: Enables all featuresminimal: Disables all optional features (default: enabled)
§Quick Start
§Using default features (coordinates + messages)
[dependencies]
windows-api-utils = "0.1"use windows_api_utils::prelude::*;
// Coordinate conversion
let window = Window::new(12345, Rect::new(100, 100, 500, 400), Default::default());
let client_point = Point::new(50, 30);
let screen_point = window.client_to_screen(client_point).unwrap();
// Message handling
let message = WindowMessage::mouse_move(100, 200, KeyModifiers::default());
if let Some(mouse_event) = MessageParser::parse_mouse_message(message) {
println!("Mouse at ({}, {})", mouse_event.x, mouse_event.y);
}§Using with windows crate interop
[dependencies]
windows-api-utils = { version = "0.1", features = ["windows-interop"] }
windows = "0.52"use windows_api_utils::prelude::*;
use windows::Win32::Foundation::{WPARAM, LPARAM};
// 完全兼容,无需转换!
let win_wparam = WPARAM(0x1234);
let our_wparam = WParam::from(win_wparam);
let back_to_win: WPARAM = our_wparam.into();
assert_eq!(win_wparam.0, back_to_win.0);
// 坐标转换测试
let win_lparam = LPARAM(0x00C80064); // x=100, y=200
let our_lparam = LParam::from(win_lparam);
let (x, y) = our_lparam.as_point();
assert_eq!(x, 100);
assert_eq!(y, 200);
// from_point -> our_lparam -> win_lparam 完整流程测试
let our_lparam_from_coords = LParam::from_point(300, 400);
let win_lparam_from_our: LPARAM = our_lparam_from_coords.into();
let (x_back, y_back) = our_lparam_from_coords.as_point();
assert_eq!(x_back, 300);
assert_eq!(y_back, 400);
// 验证转换后的值是正确的坐标编码
let expected_value = ((400 as u32) << 16) | (300 as u32);
assert_eq!(win_lparam_from_our.0 as u32, expected_value);§Using only coordinate features
[dependencies]
windows-api-utils = { version = "0.1", default-features = false, features = ["coordinates"] }use windows_api_utils::{Point, Rect, Window, CoordinateTransformer};
let window = Window::new(12345, Rect::new(100, 100, 500, 400), Default::default());
let client_point = Point::new(50, 30);
let screen_point = window.client_to_screen(client_point).unwrap();§Using only bit operations
[dependencies]
windows-api-utils = { version = "0.1", default-features = false, features = ["bit-ops"] }let value = 0x12345678;
let low = loword(value); // 0x5678
let high = hiword(value); // 0x1234
let reconstructed = make_long(high, low);§Minimal usage (no-std compatible)
[dependencies]
windows-api-utils = { version = "0.1", default-features = false }use windows_api_utils::WindowsUtilsError;
// Only error types available in minimal modeRe-exports§
pub use error::*;pub use coordinates::*;pub use messages::*;
Modules§
- coordinates
- Coordinate conversion utilities.
- error
- Error types for Windows API utilities.
- messages
- Windows message parameter handling.
- prelude
- Prelude for convenient imports based on enabled features.