1#[cfg(windows)] extern crate winapi;
15use std::io::Error;
16
17#[cfg(windows)]
18fn alert_message(head: &str,msg: &str,_wflags: i32 ) -> Result<i32, Error> {
19 use std::ffi::OsStr;
20 use std::iter::once;
21 use std::os::windows::ffi::OsStrExt;
22 use std::ptr::null_mut;
23 use winapi::um::winuser::{MB_OK, MessageBoxW};
24 let whead: Vec<u16> = OsStr::new(head).encode_wide().chain(once(0)).collect();
25 let wmsg: Vec<u16> = OsStr::new(msg).encode_wide().chain(once(0)).collect();
26 let ret = unsafe {
27 MessageBoxW(null_mut(), wmsg.as_ptr(), whead.as_ptr(), MB_OK|winapi::um::winuser::MB_ICONEXCLAMATION)
28 };
29 if ret == 0 { Err(Error::last_os_error()) }
30 else { Ok(ret) }
31}
32#[cfg(not(windows))]
33fn alert_message(head: &str,msg: &str,_wflags: i32) -> Result<(), Error> {
34 println!("{}", msg);
35 Ok(())
36}
37
38pub fn alert(head: &str,msg: &str) {
39 alert_message( head,msg,0 ).unwrap();
40}