Comments (1)
The problem is that you adding a node to the treeview control, but the control doesn't physically exist yet. That is: the treeview object has been created, but the owner window didn't render it yet.
In order to perform this operation, you must do it in the WM_CREATE
event (if an ordinary window), or in the WM_INITDIALOG
event (if a dialog window).
The example below shows you code, corrected:
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use winsafe::{prelude::*, gui, co, AnyResult, HWND};
#[derive(Clone)]
pub struct MyWindow {
wnd: gui::WindowMain,
tv: gui::TreeView,
}
impl MyWindow {
pub fn new() -> Self {
let wnd = gui::WindowMain::new(
gui::WindowMainOpts {
title: "My window title".to_owned(),
size: (300, 150),
..Default::default()
},
);
let tv = gui::TreeView::new(
&wnd,
Default::default(),
);
// tv.items().add_root("text", None); THIS LINE GOES TO WM_CREATE
let new_self = Self { wnd, tv };
new_self.events(); // add the window event handlers
new_self
}
pub fn run(&self) -> AnyResult<i32> {
self.wnd.run_main(None)
}
fn events(&self) {
let self2 = self.clone();
self.wnd.on().wm_create(move |_| { // called right after the window is created
self2.tv.items().add_root("text", None);
Ok(0)
});
}
}
fn main() {
if let Err(e) = run_app() {
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())
}
The message error doesn't help, though. I'll implement a better error handling for such case.
from winsafe.
Related Issues (20)
- WindowModal::show_modal never returns
- how to create a UpDown/Spin control HOT 6
- as_mut may be unsound HOT 1
- ListBox:: new() ListBoxOpts list_box_style field ignores co::WS::HSCROLL flag when present HOT 3
- Custom color on for class_bg_brush on WindowMainOpts HOT 1
- ...Guard::new should be unsafe and leak should not be HOT 2
- Question concerning creating a DC, getting a ListBox's selected font, and invoking GetSystemMetrics(SM_SM_CXBORDER) HOT 2
- Add EnableScrollBar function
- How to Custom msg_id ? HOT 1
- How to close a process? HOT 7
- How to pass a RECT as a parameter in MapWindowPoints? HOT 4
- FindWindow always encounters an error HOT 2
- Missing StretchDIBits from Windows GDI HOT 2
- Use microsoft windows-rs crate? HOT 2
- Add `GetVolumePathName` function HOT 2
- Linker error when calling DrawText() HOT 1
- Running a FileSaveAs dialog crashes HOT 2
- Wrong GetAsyncKeyState return type. HOT 4
- SetLayeredWindowAttributes HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from winsafe.