Module raw

Module raw 

Source
Expand description

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.

§Safety

Note that these functions are unsafe, as they assume the strings passed as message and title are and will remain valid UTF-16 and null terminated until show is called. This is especially important when passing strings created at runtime.

To create a wide string statically, use the w! macro re-exported by this module from windows_sys.

§Examples

Show a minimal message box with an OK button:

use win_msgbox::{raw::{show, w}, Okay};
unsafe { show::<Okay>(w!("Hello World")); }

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

use win_msgbox::{raw::{error, w}, CancelTryAgainContinue::{self, *}};

// Safety: `w!` creates null-terminated UTF-16 strings at compile time,
//         thus the pointed-to value never changes.
let response = unsafe {
    error::<CancelTryAgainContinue>(w!("Couldn't download resource"))
        .title(w!("Download Error"))
        .show()?
};

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

Macros§

w
A literal UTF-16 wide string with a trailing null terminator.

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.

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.