Crate win_msgbox

Source
Expand description

This crate provides a fully featured, ergonomic interface to Windows’ MessageBox.

All possible options are usable and return values are Rust enums (or structs if only one option is available).

All configuration is done through MessageBox and available buttons are configured via Options.

message and title will be converted to UTF-16 when calling show on the fly. If this isn’t desired, use the structs and functions exported in the raw module. However, note that these are unsafe, as they assume the passed pointers point to valid, null-terminated UTF-16 strings.

§Examples

Show a minimal message box with an OK button:

use win_msgbox::Okay;
win_msgbox::show::<Okay>("Hello World");

Show a message box with an error icon, and match on the return value:

use win_msgbox::CancelTryAgainContinue::{self, *};

let response = win_msgbox::error::<CancelTryAgainContinue>("Couldn't download resource")
    .title("Download Error")
    .show()?;

match response {
    Cancel => println!("Cancelling downlaod..."),
    TryAgain => println!("Attempting redownload..."),
    Continue => println!("Skipping resource"),
}

Modules§

raw
This module provides the raw functionality to avoid having to convert UTF-8 to UTF-16 when showing a message box. Otherwise, it’s identical to the main exports.

Structs§

MessageBox
A builder for a modal dialog box that contains a system icon, a set of buttons, and a brief application-specific message, such as status or error information.
Okay
The message box contains one push button: OK.

Enums§

AbortRetryIgnore
The message box contains three push buttons: Abort, Retry, and Ignore.
CancelTryAgainContinue
The message box contains three push buttons: Cancel, Try Again, Continue. Use this message box type instead of AbortRetryIgnore.
DefaultButton
Specifies the default button of the dialog box.
Icon
The icon to be displayed in a message box.
Modal
Specifies the modality of the dialog box.
OkayCancel
The message box contains two push buttons: OK and Cancel.
RetryCancel
The message box contains two push buttons: Retry and Cancel.
YesNo
The message box contains two push buttons: Yes and No.
YesNoCancel
The message box contains three push buttons: Yes, No, and Cancel.

Traits§

Options
This trait is implemented for all possible options.

Functions§

asterisk
Creates a new message box where its icon is set to Asterisk.
error
Creates a new message box where its icon is set to Error.
exclamation
Creates a new message box where its icon is set to Exclamation.
hand
Creates a new message box where its icon is set to Hand.
information
Creates a new message box where its icon is set to Information.
question
Creates a new message box where its icon is set to Question.
show
Shows a message box with a specified text to be displayed.
stop
Creates a new message box where its icon is set to Stop.
warning
Creates a new message box where its icon is set to Warning.

Type Aliases§

Error
Raw error returned by GetLastError.
Result
Convenience wrapper type for a Result<T, win_msgbox::Error>.