pub struct WindowMain(/* private fields */);gui only.Expand description
An user main window, which can handle events. Usually, this is the first
window of your application, launched directly from the main function. Can
be programmatically created or load a dialog resource from a .res file.
§Examples
Basic structure of a program with a main window, created programmatically:
use winsafe::{self as w, co, gui, prelude::*};
fn main() {
if let Err(err) = Main::create_and_run() {
w::HWND::NULL
.MessageBox(&err.to_string(), "Uncaught error", co::MB::ICONERROR)
.unwrap();
}
}
#[derive(Clone)]
struct Main {
wnd: gui::WindowMain,
}
impl Main {
#[must_use]
fn create_and_run() -> w::AnyResult<i32> {
let wnd = gui::WindowMain::new(gui::WindowMainOpts {
title: "Main window",
..Default::default()
});
let new_self = Self { wnd };
new_self.events();
new_self.wnd.run_main(None)
}
fn events(&self) {
let self2 = self.clone();
self.wnd.on().wm_create(move |_| {
self2.wnd.hwnd().SetWindowText("Hello")?;
Ok(0)
});
}
}Implementations§
Source§impl WindowMain
impl WindowMain
Sourcepub fn new(opts: WindowMainOpts<'_>) -> Self
pub fn new(opts: WindowMainOpts<'_>) -> Self
Instantiates a new WindowMain object, to be created internally with
HWND::CreateWindowEx.
Sourcepub fn new_dlg(
dlg_id: u16,
icon_id: Option<u16>,
accel_tbl_id: Option<u16>,
) -> Self
pub fn new_dlg( dlg_id: u16, icon_id: Option<u16>, accel_tbl_id: Option<u16>, ) -> Self
Instantiates a new WindowMain object, to be loaded from a dialog
resource with
HINSTANCE::CreateDialogParam.
Sourcepub fn run_main(&self, cmd_show: Option<SW>) -> AnyResult<i32>
pub fn run_main(&self, cmd_show: Option<SW>) -> AnyResult<i32>
Physically creates the window, then runs the main application loop. This method will block until the window is closed.
The cmd_show parameter defaults to
co::SW::SHOW.
§Panics
Panics if the window is already created.
Panics if the creation process fails.
Sourcepub fn on(&self) -> &impl GuiEventsParent
pub fn on(&self) -> &impl GuiEventsParent
Exposes methods to handle window messages.
§Panics
Panics if the window is already created. Events must be set before window creation.
Trait Implementations§
Source§impl Clone for WindowMain
impl Clone for WindowMain
Source§fn clone(&self) -> WindowMain
fn clone(&self) -> WindowMain
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl GuiParent for WindowMain
impl GuiParent for WindowMain
Source§fn spawn_thread<F>(&self, func: F)
fn spawn_thread<F>(&self, func: F)
std::thread::spawn, but it allows the returning of
an error value. This error value will be forwarded to the original UI
thread, allowing it to be caught at
WindowMain::run_main. Read more