Klaus
unread,May 3, 2026, 7:37:14 AM (2 days ago) May 3Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to fltk.general
Hi!
I want to create a dialog window which is modal, means it is the only
window which reacts on any kind of input. But this window should be
moveable.
All my experiments result in 2 kinds of behavior:
1. ) The window is the only one which reacts on inputs, but it can't be
moved ( without also moving the main application window )
2. ) The window is moveable, but the main window still reacts on all
kind of input which enables me to generate multiple dialog windows.
Non of both is what I need :-)
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <iostream>
void open_dialog(Fl_Widget*, void* v) {
Fl_Window* mainwin = (Fl_Window*)v;
Fl_Window* dlg = new Fl_Window(300, 200, "Dialog");
mainwin->deactivate(); // did not deactivate the main window. It
still reacts on inputs
dlg->callback([](Fl_Widget* w, void* data) {
Fl_Window* mainwin = (Fl_Window*)data;
mainwin->activate();
w->hide();
}, mainwin);
dlg->end();
dlg->show();
}
#if 0
void open_dialog(Fl_Widget*, void*) {
Fl_Window* dlg = new Fl_Window(300, 200, "Dialog");
dlg->set_modal(); // it is now modal, but not longer moveable
new Fl_Button(100, 120, 100, 30, "OK");
dlg->end();
dlg->show();
}
#endif
int main() {
Fl_Window win(400, 300, "Mainwin");
Fl_Button btn(150, 130, 100, 30, "Dialog open");
btn.callback(open_dialog, &win);
win.end();
win.show();
return Fl::run();
}
#if 0
class CustomDialog : public Fl_Window {
int selected_value;
static void button_cb(Fl_Widget* w, void* data) {
CustomDialog* dialog = (CustomDialog*)w->parent();
dialog->selected_value = (int)(long)data;
dialog->hide(); //
}
public:
CustomDialog() : Fl_Window(300, 150, "Wahl treffen"),
selected_value(-1) {
//this->set_non_modal(); // main window still reacts on inputs
but win is moveable
this->set_modal(); // main win did not react n inputs (fine)
but dialog can't be moved anymore
this->border(1);
// Drei Knöpfe mit unterschiedlichen Rückgabewerten
Fl_Button* b1 = new Fl_Button(20, 50, 80, 40, "Wert 10");
Fl_Button* b2 = new Fl_Button(110, 50, 80, 40, "Wert 20");
Fl_Button* b3 = new Fl_Button(200, 50, 80, 40, "Wert 30");
b1->callback(button_cb, (void*)10);
b2->callback(button_cb, (void*)20);
b3->callback(button_cb, (void*)30);
this->end();
}
int show_and_wait() {
this->show();
while (this->shown()) {
Fl::wait();
}
return selected_value;
}
};
void open_dialog_cb(Fl_Widget*, void*) {
Fl_Group::current(0);
CustomDialog* diag = new CustomDialog();
diag->parent(NULL);
diag->border(1);
diag->position(500, 400);
int result = diag->show_and_wait(); // Blockiert hier
if (result != -1) {
std::cout << "Coice " << result << std::endl;
} else {
std::cout << "Np choice" << std::endl;
}
delete diag;
}
int main() {
Fl_Window* main_win = new Fl_Window(400, 300, "FLTK 1.5 App");
Fl_Button* btn = new Fl_Button(150, 130, 100, 40, "Dialog");
btn->callback(open_dialog_cb);
main_win->end();
main_win->show();
return Fl::run();
}
#endif
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <iostream>
#if 0
class CustomDialog : public Fl_Window {
int result;
public:
CustomDialog() : Fl_Window(300, 150, "Völlig Frei"), result(-1) {
this->set_non_modal();
Fl_Button* b = new Fl_Button(100, 50, 100, 40, "Wert 20");
b->callback(btn_cb, (void*)20);
this->end();
}
static void btn_cb(Fl_Widget* w, void* data) {
CustomDialog* d = (CustomDialog*)w->parent();
d->result = (int)(long)data;
d->hide();
}
int run() {
Fl_Window* main_win = Fl::first_window();
if (main_win) main_win->deactivate();
this->position(100, 100);
this->show();
while (this->shown()) Fl::wait();
if (main_win) main_win->activate();
return result;
}
};
void open_cb(Fl_Widget* w, void*) {
//w->deactivate();
Fl_Window* main_win = Fl::first_window();
if (main_win) main_win->deactivate();
Fl_Group::current(0);
CustomDialog diag;
diag.run();
main_win->activate();
//w->activate();
}
int main() {
Fl_Window* win = new Fl_Window(400, 300, "Main win");
Fl_Button* btn = new Fl_Button(140, 130, 120, 40, "Dialog");
Fl_Button* btn2 = new Fl_Button(140, 160, 120, 40, "Dialog");
btn->callback(open_cb);
btn2->callback(open_cb);
win->end();
win->show();
return Fl::run();
}
#endif