extern crate winapi;
use winapi::um::winuser::{MessageBoxW, MB_ICONERROR, MB_OK, HWND_DESKTOP, MB_ICONINFORMATION};
struct WinAlert<'a> {
body: &'a str,
}
impl<'a> WinAlert<'a> {
fn new() -> WinAlert<'a> {
WinAlert { body: "" }
}
fn alert_err(body: &'a str) -> WinAlert<'a> {
unsafe {
MessageBoxW(
HWND_DESKTOP,
body.encode_utf16().chain(Some(0)).collect::<Vec<u16>>().as_ptr(),
"Critical Message\0".encode_utf16().chain(Some(0)).collect::<Vec<u16>>().as_ptr(),
MB_OK | MB_ICONERROR,);
}
WinAlert {body}
}
fn alert_info(body: &'a str) ->WinAlert<'a> {
unsafe {
MessageBoxW(
HWND_DESKTOP,
body.encode_utf16().chain(Some(0)).collect::<Vec<u16>>().as_ptr(),
"Information Message\0".encode_utf16().chain(Some(0)).collect::<Vec<u16>>().as_ptr(),
MB_OK | MB_ICONINFORMATION,);
}
WinAlert {body}
}
}