So far, I came up with two solutions:
1. global (lazy, f*ck it) approach: make Window IDs global. I maintain a list of global window IDs with one window ID for each window that needs to be accessed somewhere. The benefit is that I never have to think how to pass that needed window ID / pointer to the respective window. A macro-wrapped call of wxWindow::FindWindowById() is all I need then. Furthermore, I do rarely need to derive classes from wxWidgets standard window classes. I just need to configure an instance of the respective standard class since it does not need to store the window IDs / pointers of its accessed windows. The downside are the perils when using global variables. For instance, from the outside it is not clear what resources
Code: Select all
wxFrame* CreateMainWindow(wxString const& title);
2. local (clean, crafted) approach: this is what I see often in the wxWidgets samples. Each window class has pointers to the other windows in the hierarchy it needs to access. The downside is, this requires deriving from the standard wxWidgets window classes since those pointers have to be stored somewhere (namely in the derived class). It makes setting up the whole hierarchy also somewhat complicated if you realize somewhere in the implementation that you need to access that grand-grand-grand-child of the 6th sibling of your grand-grand-grand-parent window to implement a feature. The good side is, that if you managed to do it right, you have no hidden global variables in your hierarchy. You could then call
Code: Select all
new MyFrame {/* all your needed parameters */};
To make a long story short: What is the preferred (canonical, wxWidgets-esque) style of accessing windows in a non-trivial application? Is the global approach frowned upon? Should I "fumble" through the local approach instead?