#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Menu_Bar.H>
#include <iostream>
static int shown_v;
class my_win : public Fl_Double_Window {
int handle(int);
int please_change;
public:
my_win(int x, int y,int w,int h,const char* L):Fl_Double_Window(x,y,w,h,L), please_change(0) {};
}; // my_win
int my_win::handle (int e){
int ret = Fl_Double_Window::handle(e);
if (e == FL_KEYBOARD) {
if (Fl::event_state() & (FL_ALT)) {
if (Fl::event_key()=='s') {
please_change = (-1);
return 1;
}
}
}
else if (e == FL_KEYUP) {
if (please_change) {
if (shown_v) {
this->hide();
shown_v = 0;
}
else {
this->show();
shown_v = 1;
}
please_change = 0;
return 1;
}
}
return ret;
} // my_win::handle
void toggle_win (Fl_Widget*,void* data) {
my_win* w = static_cast<my_win*>(data);
if (shown_v) {
w->hide();
shown_v = 0;
}
else {
w->show();
shown_v = 1;
}
} // toggle_win
int main() {
shown_v = 0;
my_win *win2 = new my_win(0.5*Fl::w()-100,0.5*Fl::h()-100,200,200,"Second win");
win2->end();
Fl_Double_Window *win = new Fl_Double_Window(0.5*Fl::w()-200,0.5*Fl::h()-200,400,400,"Main Win");
win->begin();
Fl_Menu_Item items[] = {
{"Menu1",0,0,0,FL_SUBMENU,0,0,FL_NORMAL_SIZE,FL_BLACK}, //0
{"Hide/show second window",FL_ALT+'s',toggle_win,win2,0,0,0,FL_NORMAL_SIZE,FL_BLACK},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}
};
Fl_Menu_Bar *menu = new Fl_Menu_Bar(0, 0, win->w(),25);
menu->menu(items);
win->end();
win->show();
return Fl::run();
} // main
// end of file