win_msgbox_timeout 1.2.1

Windows message boxes and notification helpers with timeout for Rust
Documentation
  • Coverage
  • 100%
    25 out of 25 items documented1 out of 1 items with examples
  • Size
  • Source code size: 68.74 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.24 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 46s Average build duration of successful builds.
  • all releases: 54s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Mikachu2333/win_msgbox_timeout
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Mikachu2333

win_msgbox_timeout

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_w for direct calling from C/C++ code

Platform

  • Windows only
  • Uses raw Win32 FFI (User32, Shell32, Gdi32)

Installation

Add to your Cargo.toml:

[dependencies]

win_msgbox_timeout = "1.2.0"

Quick Start

use win_msgbox_timeout::{
    MsgBoxType, MsgBtnType, custom_msgbox, error_msgbox, info_msgbox, notify_msgbox_standalone,
    quest_msgbox_yesno, wait_notifications, warn_msgbox,
};

fn main() {
    info_msgbox("Hello from Rust", "Info", 0);
    warn_msgbox("Careful!", "Warning", 3000);

    let result = quest_msgbox_yesno("Do you want to continue?", "Question", 0);
    if result == 6 {
        info_msgbox("You clicked Yes", "Result", 0);
    } else if result == 7 {
        error_msgbox("You clicked No", "Result", 0);
    }

    custom_msgbox(
        "Custom msg (Msg types, btn types and custom timeout are also available)",
        "Custom title",
        MsgBoxType::Warn,
        MsgBtnType::OkCancel,
        0,
    );

    notify_msgbox_standalone("Task", "Operation completed", 5000);

    // Wait for standalone notifications before process exit.
    wait_notifications();
}

API Overview

Message Boxes

  • info_msgbox(msg, title, timeout_ms) -> i32
  • error_msgbox(msg, title, timeout_ms) -> i32
  • warn_msgbox(msg, title, timeout_ms) -> i32
  • quest_msgbox_yesno(msg, title, timeout_ms) -> i32
  • quest_msgbox_okcancel(msg, title, timeout_ms) -> i32
  • custom_msgbox(msg, title, msgbox_type, msgboxbtn_type, timeout_ms) -> i32

Return values follow Win32 MessageBox conventions:

  • 1: OK
  • 2: Cancel
  • 6: Yes
  • 7: No
  • -1: closed by timeout

Standalone Notification Popup

  • notify_msgbox_standalone(title, msg, timeout_ms) -> bool
  • wait_notifications()

Tray Balloon Helper

  • notify_msgbox(hwnd, msg, icon_id) -> i32

Notes:

  • notify_msgbox requires an existing tray icon created with the same icon_id.
  • NotifyIconType enum 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_Error = 0x0010,
    MsgBoxType_Info  = 0x0040,
    MsgBoxType_Quest = 0x0020,
    MsgBoxType_Warn  = 0x0030,
} MsgBoxType;

typedef enum {
    MsgBtnType_Ok       = 0x0000,
    MsgBtnType_OkCancel = 0x0001,
    MsgBtnType_YesNo    = 0x0004,
} MsgBtnType;

__declspec(dllimport) int __stdcall custom_msgbox_w(
    const wchar_t* msg,
    const wchar_t* title,
    unsigned int msgbox_type,
    unsigned int msgboxbtn_type,
    unsigned long long timeout_ms
);

C++ Example

#include <iostream>

extern "C" int __stdcall custom_msgbox_w(
    const wchar_t* msg, const wchar_t* title,
    unsigned int msgbox_type, unsigned int msgboxbtn_type,
    unsigned long long timeout_ms
);

int main() {
    int result = custom_msgbox_w(
        L"Hello from C++!",
        L"FFI Demo",
        0x0040, // Info
        0x0000, // OK
        5000    // 5-second timeout
    );
    std::cout << "Result: " << result << std::endl;
    return 0;
}

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

  1. Create a crates.io account and API token.

  2. Log in from terminal:

    cargo login <YOUR_CRATES_IO_TOKEN>
    
  3. Validate package locally:

    cargo fmt --check
    cargo clippy -- -D warnings
    cargo package
    
  4. Publish:

    cargo publish
    
  5. Verify:

    cargo search win_msgbox
    

Notes Before Publishing

  • Ensure the version in Cargo.toml is new (cannot republish same version).
  • Make sure license, description, and readme are present.
  • Consider adding repository when you have a public Git repository URL.

License

MIT