windows_api_utils/lib.rs
1//! Windows API utilities for coordinate conversion, bit operations, and message parameter handling.
2//!
3//! This crate provides utilities for working with Windows API concepts including:
4//! - Coordinate conversion between client and screen coordinates
5//! - Bit manipulation (LOWORD, HIWORD, LOBYTE, HIBYTE)
6//! - Windows message parameter handling (WPARAM, LPARAM)
7//!
8//! # Features
9//!
10//! - **Coordinate Conversion**: ClientToScreen, ScreenToClient functionality
11//! - **Bit Manipulation**: Extract high/low words and bytes from integers
12//! - **Message Parameters**: Type-safe WPARAM and LPARAM handling
13//! - **Cross-platform**: Works on Windows, Linux, and macOS
14//! - **No-std support**: Core functionality available without std
15//! - **Feature Gating**: Enable only the functionality you need
16//! - **Serialization**: Optional serde support for message types
17//!
18//! # Feature Flags
19//!
20//! - `coordinates`: Enables coordinate conversion types and traits
21//! - `bit-ops`: Enables bit manipulation utilities
22//! - `messages`: Enables Windows message handling
23//! - `serde`: Enables serialization support for types
24//! - `full`: Enables all features
25//! - `minimal`: Disables all optional features (default: enabled)
26//!
27//! # Quick Start
28//!
29//! ## Using default features (coordinates + messages)
30//!
31//! ```toml
32//! [dependencies]
33//! windows-api-utils = "0.1"
34//! ```
35//!
36//! ```rust
37//! use windows_api_utils::prelude::*;
38//!
39//! // Coordinate conversion
40//! let window = Window::new(12345, Rect::new(100, 100, 500, 400), Default::default());
41//! let client_point = Point::new(50, 30);
42//! let screen_point = window.client_to_screen(client_point).unwrap();
43//!
44//! // Message handling
45//! let message = WindowMessage::mouse_move(100, 200, KeyModifiers::default());
46//! if let Some(mouse_event) = MessageParser::parse_mouse_message(message) {
47//! println!("Mouse at ({}, {})", mouse_event.x, mouse_event.y);
48//! }
49//! ```
50//!
51//! ## Using only coordinate features
52//!
53//! ```toml
54//! [dependencies]
55//! windows-api-utils = { version = "0.1", default-features = false, features = ["coordinates"] }
56//! ```
57//!
58//! ```rust
59//! use windows_api_utils::{Point, Rect, Window, CoordinateTransformer};
60//!
61//! let window = Window::new(12345, Rect::new(100, 100, 500, 400), Default::default());
62//! let client_point = Point::new(50, 30);
63//! let screen_point = window.client_to_screen(client_point).unwrap();
64//! ```
65//!
66//! ## Using only bit operations
67//!
68//! ```toml
69//! [dependencies]
70//! windows-api-utils = { version = "0.1", default-features = false, features = ["bit-ops"] }
71//! ```
72//!
73//! ```rust
74//! use windows_api_utils::{loword, hiword, make_long, BitUtils};
75//!
76//! let value = 0x12345678;
77//! let low = loword(value); // 0x5678
78//! let high = hiword(value); // 0x1234
79//! let reconstructed = make_long(high, low);
80//! ```
81//!
82//! ## Minimal usage (no-std compatible)
83//!
84//! ```toml
85//! [dependencies]
86//! windows-api-utils = { version = "0.1", default-features = false }
87//! ```
88//!
89//! ```rust
90//! use windows_api_utils::WindowsUtilsError;
91//!
92//! // Only error types available in minimal mode
93//! ```
94
95#![cfg_attr(not(feature = "std"), no_std)]
96#![warn(missing_docs)]
97
98// Core modules - always available
99pub mod error;
100
101// Feature-gated modules
102#[cfg(feature = "coordinates")]
103pub mod coordinates;
104
105#[cfg(feature = "bit-ops")]
106pub mod bit_ops;
107
108#[cfg(feature = "messages")]
109pub mod messages;
110
111// Re-export error types (always available)
112pub use error::*;
113
114// Conditional re-exports based on features
115#[cfg(feature = "coordinates")]
116pub use coordinates::*;
117
118#[cfg(feature = "bit-ops")]
119pub use bit_ops::*;
120
121#[cfg(feature = "messages")]
122pub use messages::*;
123
124/// Prelude for convenient imports based on enabled features.
125pub mod prelude {
126 pub use crate::WindowsUtilsError;
127 pub use crate::WindowsUtilsResult;
128
129 #[cfg(feature = "coordinates")]
130 pub use crate::{CoordinateTransformer, Point, Rect, Window, WindowStyle};
131
132 #[cfg(feature = "bit-ops")]
133 pub use crate::{hibyte, hiword, lobyte, loword, make_long, make_word, BitUtils, LowHighWord};
134
135 #[cfg(feature = "messages")]
136 pub use crate::{
137 windows_messages, KeyEvent, KeyModifiers, LParam, MessageParser, MouseButton, MouseEvent,
138 WParam, WindowMessage, LPARAM, LRESULT, WPARAM,
139 };
140}