Skip to content

Commit

Permalink
Main fn improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigocfd committed Mar 30, 2024
1 parent c1fdb5b commit 362f84c
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 83 deletions.
12 changes: 3 additions & 9 deletions 02_native_controls/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32> {
MyWindow::new()
.run()
.map_err(|err| err.into())
}
4 changes: 2 additions & 2 deletions 02_native_controls/src/my_window.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use winsafe::{prelude::*, gui, AnyResult};
use winsafe::{self as w, prelude::*, gui};

#[derive(Clone)]
pub struct MyWindow {
Expand Down Expand Up @@ -135,7 +135,7 @@ impl MyWindow {
new_self
}

pub fn run(&self) -> AnyResult<i32> {
pub fn run(&self) -> w::AnyResult<i32> {
self.wnd.run_main(None)
}

Expand Down
2 changes: 2 additions & 0 deletions 03_dialog_resources/src/ids.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
12 changes: 3 additions & 9 deletions 03_dialog_resources/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32> {
MyWindow::new()
.run()
.map_err(|err| err.into())
}
2 changes: 1 addition & 1 deletion 03_dialog_resources/src/my_modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
4 changes: 2 additions & 2 deletions 03_dialog_resources/src/my_window.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use winsafe::{prelude::*, gui, AnyResult};
use winsafe::{self as w, prelude::*, gui};

use crate::ids;
use crate::my_modal::MyModal;
Expand Down Expand Up @@ -26,7 +26,7 @@ impl MyWindow {
new_self
}

pub fn run(&self) -> AnyResult<i32> {
pub fn run(&self) -> w::AnyResult<i32> {
self.wnd.run_main(None)
}

Expand Down
12 changes: 3 additions & 9 deletions 04_custom_control/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32> {
MyWindow::new()
.run()
.map_err(|err| err.into())
}
18 changes: 3 additions & 15 deletions 05_resizable_layout/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32> {
MyWindow::new()
.run()
.map_err(|err| err.into())
}
18 changes: 3 additions & 15 deletions 06_tabs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32> {
MyWindow::new()
.run()
.map_err(|err| err.into())
}
1 change: 0 additions & 1 deletion 06_tabs/src/tab_container1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
28 changes: 9 additions & 19 deletions 07_video_playback/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32> {
let _com_lib = w::CoInitializeEx(
co::COINIT::APARTMENTTHREADED
| co::COINIT::DISABLE_OLE1DDE)?;

wnd_main::WndMain::new()
.run()
.map_err(|err| err.into())
}
2 changes: 1 addition & 1 deletion 07_video_playback/src/wnd_main/wnd_main_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
});
Expand Down

0 comments on commit 362f84c

Please sign in to comment.