2

I'm using the wxGlade designer to generate the GUI for a small application. It generates a class, inherited from wxFrame, which is the main application window. In order to facilitate the maintenance, I'd like to avoid writing additional code in this generated class.

But all the widgets created with the wxGlade are actually created in the auto-generated method do_layout() and it is not possible to access them outside the scope of that generated method in the generated class.

Is there a way to get pointer of certain widget outside that generated class - by name, by type, by enumerating the children or something like that?

4

3 回答 3

3

All classes inherited from wxWindow (wxFrame being one of them) have a function "GetChildren", which returns a list of child windows that you can then enumerate over. If you are looking for a specific field by name then use the "FindWindow" function.

于 2008-10-08T13:39:35.440 回答
1

Actually I found the answer myself:

wxWindowList & children = myframe->GetChildren();
for ( wxWindowList::Node *node = children.GetFirst(); node; node = node->GetNext() )
{
     wxWindow *current = (wxWindow *)node->GetData();

     // .. do something with current
}
于 2008-10-08T13:42:02.893 回答
-1

May I recommend you try wxFormBuilder. I also used wxGlade before, but it presents too much constraints on how you use it. For example, with wxFormBuilder you can select 'visibility' (public,protected,private) for each control on the form. It can also generate virtual functions for event handlers, so you just derive your class from wxFormBuilder generated class and implement those functions.

于 2008-10-22T05:41:49.363 回答