pub struct WindowMain(/* private fields */);
Available on crate feature
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".to_owned(),
..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.
Trait Implementations§
Source§impl Clone for WindowMain
impl Clone for WindowMain
Source§fn clone(&self) -> WindowMain
fn clone(&self) -> WindowMain
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl GuiParent for WindowMain
impl GuiParent for WindowMain
Source§fn on(&self) -> &WindowEvents
fn on(&self) -> &WindowEvents
Exposes methods to handle the basic window messages, plus timer and
native control notifications. Read more
Source§fn spawn_thread<F>(&self, func: F)
fn spawn_thread<F>(&self, func: F)
This method calls
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 moreSource§impl GuiWindow for WindowMain
impl GuiWindow for WindowMain
impl Send for WindowMain
Auto Trait Implementations§
impl Freeze for WindowMain
impl !RefUnwindSafe for WindowMain
impl !Sync for WindowMain
impl Unpin for WindowMain
impl !UnwindSafe for WindowMain
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more