Greg Ercolano schrieb: > void ShowWidgets_CB(Fl_Widget *w, void*) { > Fl_Window *win = w->window(); // get button's parent window > for ( int i=0; i<win->children(); i++ ) { // walk all window's children > const char *classname = "?"; > Fl_Widget *w = win->child(i); > // Determine the class name of each widget > if ( dynamic_cast< Fl_Button*>(w) ) { classname = "Fl_Button"; > } > else if ( dynamic_cast< Fl_Box*>(w) ) { classname = "Fl_Box"; } > else if ( dynamic_cast< Fl_Input*>(w) ) { classname = "Fl_Input"; } > else if ( dynamic_cast< MyClass*>(w) ) { classname = "MyClass"; } > printf("child #%d: %s\n", i, classname); > } > }
You forgot, that programmers *love* recursions! void Recur(Fl_Group *pG) { for ( int i=0; i<pG->children(); i++ ) { // walk all groups children const char *classname = "?"; Fl_Widget *w = win->child(i); if (Fl_Group* pR= dynamic_cast< Fl_Group* >(w)) Recur(pR); // Yes, that's it! :O) else { > // Determine the class name of each widget > if ( dynamic_cast< Fl_Button*>(w) ) { classname = "Fl_Button"; } > else if ( dynamic_cast< Fl_Box*>(w) ) { classname = "Fl_Box"; } > else if ( dynamic_cast< Fl_Input*>(w) ) { classname = "Fl_Input"; } > else if ( dynamic_cast< MyClass*>(w) ) { classname = "MyClass"; } > printf("child #%d: %s\n", i, classname); > } > } } I'm not sure, wether all the brackets are right, but even if not compilable this should show the idea. _______________________________________________ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk