The hack approach: declare cards globally and use it as needed.
Fl_Tabs *cards;
void but1_Callback(...) {
...
cards = new Fl_Tabs(40,40,300,200);
...
void showCards(Fl_Widget *w, void *data) {
cards->show();
}
The FLTK callback data approach:
void but1_Callback(...) {
...
Fl_Tabs *cards = new Fl_Tabs(40,40,300,200);
menu_items[1].user_data_ = cards; // provide cards pointer as callback data
rog->menu(menu_items); // need to use menu_items AFTER modifying it
...
void showCards(Fl_Widget *w, void *data) {
Fl_Tabs *cards = static_cast<Fl_Tabs *>(data); // please the compiler by casting void * to cards *
cards->show();
}
Here is a fully "working" version [working in quotes because showCards() is correctly invoked with cards as the data parameter, but cards->show() has no effect...]
int main(int argc, char **argv) { Fl_Window *window1 = new Fl_Window(200,200,"Roger's Window"); int x = 0; int y = 0; Fl_Radio_Round_Button *but1 = new Fl_Radio_Round_Button(x+15, y+1*20, 70, 15, "SYSTEM"); but1->callback(but1_Callback); window1->show(); Fl::run(); }
Not sure how the code below comes across but if any one could help I would appreciate it. Just cannot figure out how to do this (not a C++ programmer).
My main() shows window1. A click on a button invokes but1_Callback which creates window2 that has built a menu and some tabs. The tabs are hidden and when you select a menu option it calls ShowCards() where I want to be able to cards->show. I get a "cards was not declared in this scope" error from g++.
Comments are owned by the poster. All other content is copyright 1998-2025 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.