Closed MDZZDYXCMDZZDYXC closed 10 months ago
I understand what you mean, the wm_create function is called differently in these two cases of creating forms. wm_init_dialog will be called repeatedly when the form is enlarged or reduced, etc. I have the need to load the configuration file when the form is launched. Without using the designer.res file, wm_create function is sufficient. Of course, I can implement the requirement in wm_init_dialog if I set a flag. What I want is to have an event or a function that only executes once when the program starts. One of the following codes triggers wm create and the other does not.
fn main() {
let window = gui::WindowMain::new(
gui::WindowMainOpts{
title:"test1".into(),
..Default::default()
}
);
window.on().wm_create(|_|{
println!("message");
Ok(0)
});
window.run_main(None);
}
fn main() {
let window = gui::WindowMain::new_dlg(108, Some(128), None);
window.on().wm_create(|_|{
println!("message");
Ok(0)
});
window.run_main(None);
}
Maybe I didn't describe it very well. I would like to have a more uniform event where the configuration is loaded onto the form after it is created rather than being called repeatedly.
wm_init_dialog will be called repeatedly when the form is enlarged or reduced, etc.
Not at all... WM_INITDIALOG
is called only once, immediately before the dialog is shown. There is no other situation where it's called.
Please post your code, so we can try to spot the problem.
Strange, I tried to reproduce the phenomenon again, but the code worked fine. I guarantee that I encountered this situation, maybe it was affected by some system Settings, and if I encounter this situation again, I will describe it in as much detail as possible. In both cases, I just upgraded rust to 1.74. But now there is a new problem, init_dialog does not work, the code is as follows:
use winsafe::gui;
use winsafe::prelude::*;
fn main() {
let window = gui::WindowMain::new(
gui::WindowMainOpts{
title:"test1".into(),
..Default::default()
}
);
window.on().wm_init_dialog(|_|{
println!("hello");
Ok(true)
});
window.run_main(None);
}
But now there is a new problem, init_dialog does not work, the code is as follows
There are 2 types of window, normal and dialog.
WindowMain::new
, responds to wm_create
;WindowMain::new_dlg
, responds to wm_init_dialog
.You're creating a normal window, and trying to handle wm_init_dialog
.
winsafe = "0.0.18"