win_msgbox
A small Rust library for multiple native Windows message boxes and notification popups with timeout.
Features
- Native Win32 message boxes with icon and button presets
- Optional auto-close timeout for message boxes
- Standalone popup notification window (bottom-right corner)
- Balloon tip helper for existing tray icons
- C/C++ FFI: Expose
custom_msgbox_wfor direct calling from C/C++ code
Platform
- Windows only
- Uses raw Win32 FFI (User32, Shell32, Gdi32)
Installation
Add to your Cargo.toml:
[]
= "1.2.0"
Quick Start
use ;
API Overview
Message Boxes
info_msgbox(msg, title, timeout_ms) -> i32error_msgbox(msg, title, timeout_ms) -> i32warn_msgbox(msg, title, timeout_ms) -> i32quest_msgbox_yesno(msg, title, timeout_ms) -> i32quest_msgbox_okcancel(msg, title, timeout_ms) -> i32custom_msgbox(msg, title, msgbox_type, msgboxbtn_type, timeout_ms) -> i32
Return values follow Win32 MessageBox conventions:
1: OK2: Cancel6: Yes7: No-1: closed by timeout
Standalone Notification Popup
notify_msgbox_standalone(title, msg, timeout_ms) -> boolwait_notifications()
Tray Balloon Helper
notify_msgbox(hwnd, msg, icon_id) -> i32
Notes:
notify_msgboxrequires an existing tray icon created with the sameicon_id.NotifyIconTypeenum is exported for future extension.
C/C++ FFI
When built with crate-type = ["cdylib"] (already configured), the crate generates a
.dll that can be called directly from C/C++ code.
Build the DLL
cargo build --release
The output win_msgbox_timeout.dll (and optionally .lib) will be in target/release/.
C/C++ Declaration
// Link with win_msgbox_timeout.lib
typedef enum MsgBoxType;
typedef enum MsgBtnType;
__declspec int __stdcall ;
C++ Example
extern "C" int ;
int
Running Tests
cargo test
The test suite covers:
- Enum flag values (
MsgBtnType,MsgBoxType) - Display formatting for default titles
- Text normalization (line endings, trimming)
- UTF-16 conversion (
to_wide) - Timeout closer thread behavior
- FFI null pointer safety
- Notification spawning and cleanup
Publish to crates.io
-
Create a crates.io account and API token.
-
Log in from terminal:
cargo login <YOUR_CRATES_IO_TOKEN> -
Validate package locally:
cargo fmt --check cargo clippy -- -D warnings cargo package -
Publish:
cargo publish -
Verify:
cargo search win_msgbox
Notes Before Publishing
- Ensure the version in
Cargo.tomlis new (cannot republish same version). - Make sure
license,description, andreadmeare present. - Consider adding
repositorywhen you have a public Git repository URL.
License
MIT