diff --git a/02_native_controls/src/main.rs b/02_native_controls/src/main.rs index 173adf4..f4b6799 100644 --- a/02_native_controls/src/main.rs +++ b/02_native_controls/src/main.rs @@ -2,18 +2,12 @@ mod my_window; -use winsafe::{prelude::*, co, AnyResult, HWND}; +use winsafe::{self as w, prelude::*, co}; use my_window::MyWindow; fn main() { - if let Err(e) = run_app() { - HWND::NULL.MessageBox( + if let Err(e) = (|| MyWindow::new().run())() { + w::HWND::NULL.MessageBox( &e.to_string(), "Uncaught error", co::MB::ICONERROR).unwrap(); } } - -fn run_app() -> AnyResult { - MyWindow::new() - .run() - .map_err(|err| err.into()) -} diff --git a/02_native_controls/src/my_window.rs b/02_native_controls/src/my_window.rs index b30e3a4..29527e6 100644 --- a/02_native_controls/src/my_window.rs +++ b/02_native_controls/src/my_window.rs @@ -1,4 +1,4 @@ -use winsafe::{prelude::*, gui, AnyResult}; +use winsafe::{self as w, prelude::*, gui}; #[derive(Clone)] pub struct MyWindow { @@ -135,7 +135,7 @@ impl MyWindow { new_self } - pub fn run(&self) -> AnyResult { + pub fn run(&self) -> w::AnyResult { self.wnd.run_main(None) } diff --git a/03_dialog_resources/src/ids.rs b/03_dialog_resources/src/ids.rs index e4da7cb..fc77cba 100644 --- a/03_dialog_resources/src/ids.rs +++ b/03_dialog_resources/src/ids.rs @@ -1,4 +1,6 @@ //! IDs of the resources defined in "resources\example03.res". +//! +//! They are the "glue" between our Rust code and the dialog resources. use winsafe::seq_ids; diff --git a/03_dialog_resources/src/main.rs b/03_dialog_resources/src/main.rs index d1c6202..b10ee59 100644 --- a/03_dialog_resources/src/main.rs +++ b/03_dialog_resources/src/main.rs @@ -4,18 +4,12 @@ mod my_window; mod my_modal; mod ids; -use winsafe::{prelude::*, co, AnyResult, HWND}; +use winsafe::{self as w, prelude::*, co}; use my_window::MyWindow; fn main() { - if let Err(e) = run_app() { - HWND::NULL.MessageBox( + if let Err(e) = (|| MyWindow::new().run())() { + w::HWND::NULL.MessageBox( &e.to_string(), "Uncaught error", co::MB::ICONERROR).unwrap(); } } - -fn run_app() -> AnyResult { - MyWindow::new() - .run() - .map_err(|err| err.into()) -} diff --git a/03_dialog_resources/src/my_modal.rs b/03_dialog_resources/src/my_modal.rs index 8ebc823..37da25e 100644 --- a/03_dialog_resources/src/my_modal.rs +++ b/03_dialog_resources/src/my_modal.rs @@ -77,7 +77,7 @@ impl MyModal { }); let self2 = self.clone(); - self.wnd.on().wm_command_accel_menu(co::DLGID::CANCEL.into(), move || { // ESC key + self.wnd.on().wm_command_accel_menu(co::DLGID::CANCEL, move || { // ESC key *self2.return_val.try_borrow_mut()? = None; // no return text self2.wnd.hwnd().EndDialog(0)?; Ok(()) diff --git a/03_dialog_resources/src/my_window.rs b/03_dialog_resources/src/my_window.rs index 9ada097..9e7c1f0 100644 --- a/03_dialog_resources/src/my_window.rs +++ b/03_dialog_resources/src/my_window.rs @@ -1,4 +1,4 @@ -use winsafe::{prelude::*, gui, AnyResult}; +use winsafe::{self as w, prelude::*, gui}; use crate::ids; use crate::my_modal::MyModal; @@ -26,7 +26,7 @@ impl MyWindow { new_self } - pub fn run(&self) -> AnyResult { + pub fn run(&self) -> w::AnyResult { self.wnd.run_main(None) } diff --git a/04_custom_control/src/main.rs b/04_custom_control/src/main.rs index e432f35..f55288a 100644 --- a/04_custom_control/src/main.rs +++ b/04_custom_control/src/main.rs @@ -3,18 +3,12 @@ mod my_window; mod click_board; -use winsafe::{prelude::*, co, AnyResult, HWND}; +use winsafe::{self as w, prelude::*, co}; use my_window::MyWindow; fn main() { - if let Err(e) = run_app() { - HWND::NULL.MessageBox( + if let Err(e) = (|| MyWindow::new().run())() { + w::HWND::NULL.MessageBox( &e.to_string(), "Uncaught error", co::MB::ICONERROR).unwrap(); } } - -fn run_app() -> AnyResult { - MyWindow::new() - .run() - .map_err(|err| err.into()) -} diff --git a/05_resizable_layout/src/main.rs b/05_resizable_layout/src/main.rs index 9a51876..f4b6799 100644 --- a/05_resizable_layout/src/main.rs +++ b/05_resizable_layout/src/main.rs @@ -6,20 +6,8 @@ use winsafe::{self as w, prelude::*, co}; use my_window::MyWindow; fn main() { - if let Err(e) = run_app() { - w::HWND::NULL.TaskDialog( - None, - Some("Unhandled error"), - None, - Some(&e.to_string()), - co::TDCBF::OK, - w::IconRes::Error, - ).unwrap(); + if let Err(e) = (|| MyWindow::new().run())() { + w::HWND::NULL.MessageBox( + &e.to_string(), "Uncaught error", co::MB::ICONERROR).unwrap(); } } - -fn run_app() -> w::AnyResult { - MyWindow::new() - .run() - .map_err(|err| err.into()) -} diff --git a/06_tabs/src/main.rs b/06_tabs/src/main.rs index 8f4afff..aba49ad 100644 --- a/06_tabs/src/main.rs +++ b/06_tabs/src/main.rs @@ -8,20 +8,8 @@ use winsafe::{self as w, prelude::*, co}; use my_window::MyWindow; fn main() { - if let Err(e) = run_app() { - w::HWND::NULL.TaskDialog( - None, - Some("Unhandled error"), - None, - Some(&e.to_string()), - co::TDCBF::OK, - w::IconRes::Error, - ).unwrap(); + if let Err(e) = (|| MyWindow::new().run())() { + w::HWND::NULL.MessageBox( + &e.to_string(), "Uncaught error", co::MB::ICONERROR).unwrap(); } } - -fn run_app() -> w::AnyResult { - MyWindow::new() - .run() - .map_err(|err| err.into()) -} diff --git a/06_tabs/src/tab_container1.rs b/06_tabs/src/tab_container1.rs index 31a1883..1b2a883 100644 --- a/06_tabs/src/tab_container1.rs +++ b/06_tabs/src/tab_container1.rs @@ -50,7 +50,6 @@ impl TabContainer1 { let self2 = self.clone(); self.btn.on().bn_clicked(move || { self2.wnd.hwnd().GetParent()?.TaskDialog( - None, Some("Hello"), None, Some(&self2.txt.text()), diff --git a/07_video_playback/src/main.rs b/07_video_playback/src/main.rs index c0a9318..4929fdf 100644 --- a/07_video_playback/src/main.rs +++ b/07_video_playback/src/main.rs @@ -7,24 +7,14 @@ mod wnd_tracker; mod wnd_video; fn main() { - if let Err(e) = run_main_window() { - w::HWND::NULL.TaskDialog( - None, - Some("Unhandled error"), - None, - Some(&e.to_string()), - co::TDCBF::OK, - w::IconRes::Error, - ).unwrap(); + if let Err(e) = (|| { + let _com_lib = w::CoInitializeEx( + co::COINIT::APARTMENTTHREADED + | co::COINIT::DISABLE_OLE1DDE, + )?; + wnd_main::WndMain::new().run() + })() { + w::HWND::NULL.MessageBox( + &e.to_string(), "Uncaught error", co::MB::ICONERROR).unwrap(); } } - -fn run_main_window() -> w::AnyResult { - let _com_lib = w::CoInitializeEx( - co::COINIT::APARTMENTTHREADED - | co::COINIT::DISABLE_OLE1DDE)?; - - wnd_main::WndMain::new() - .run() - .map_err(|err| err.into()) -} diff --git a/07_video_playback/src/wnd_main/wnd_main_events.rs b/07_video_playback/src/wnd_main/wnd_main_events.rs index f889a8d..862f86a 100644 --- a/07_video_playback/src/wnd_main/wnd_main_events.rs +++ b/07_video_playback/src/wnd_main/wnd_main_events.rs @@ -11,7 +11,7 @@ impl WndMain { }); let wnd = self.wnd.clone(); - self.wnd.on().wm_command_accel_menu(co::DLGID::CANCEL.into(), move || { + self.wnd.on().wm_command_accel_menu(co::DLGID::CANCEL, move || { wnd.close(); // close on ESC Ok(()) });