Usually, wxWidgets seems to handle pointers quite well. I'm using it now to create a level designer for my graphics engine which uses shared_ptr's for everything and I'd like to use them for my wxWidgets windows as well as I don't like mixing raw and managed pointers.
What's the correct way of doing this in wxWidgets?
Using std::shared_ptr with wxWidgets
-
- I live to help wx-kind
- Posts: 187
- Joined: Sun Jan 30, 2005 2:50 pm
- Location: Heidelberg, Germany
Using std::shared_ptr with wxWidgets
Windows 7 Pro
Visual Studio 2010
wxWidgets 2.9.3
Visual Studio 2010
wxWidgets 2.9.3
I'd say you can use shared_ptr with wxWindow but you shouldn't need to.
Deleting a wxWindow is always handled by its parent, and parent-less ones (top level windows) are normally deleted by the app. So you don't need to manage the pointers of wxWindow-s.
Maybe there are exceptions, like context menus, but they can be created on the stack so again, no managing is necessary.
You can however delete a wxWindow on your own, the only drawback should be that a wxWindowDestroyEvent will not be sent for that window
Deleting a wxWindow is always handled by its parent, and parent-less ones (top level windows) are normally deleted by the app. So you don't need to manage the pointers of wxWindow-s.
Maybe there are exceptions, like context menus, but they can be created on the stack so again, no managing is necessary.
You can however delete a wxWindow on your own, the only drawback should be that a wxWindowDestroyEvent will not be sent for that window
You would need a special shared pointer implementation; it would need to call ->Destroy() and not delete, and as well detach the window from any sizer it was added to.
I wouldn't recommend trying to do it this way, except for top-level components perhaps
I wouldn't recommend trying to do it this way, except for top-level components perhaps
"Keyboard not detected. Press F1 to continue"
-- Windows
-- Windows