我正在使用FLTK。我有一个带有各种按钮的窗口,用户可以单击这些按钮来执行一些操作。在我的int main()中,我有一个switch语句来处理所有这些问题。当用户单击exit时,switch语句的设置如下:
case Exit_program:
cout << "save files and exit\n";
do_save_exit(sw);这将转到do_save_exit函数,该函数创建一个带有两个按钮yes (退出)和no (不退出)的退出确认窗口。我让yes按钮工作,退出程序,但no按钮意味着我应该只隐藏确认窗口。这是以下函数:
void yes(Address addr, Address)
{
exit(0);
}
void no(Address addr, Address)
{
}
void do_save_exit(Window& w)
{
Window quit(Point(w.x()+100, w.y()+100), 250, 55, "Exit confirmation");
Text conf(Point(15,15),"Do you really want to save and exit?");
Button yes(Point(60, 20),35,30,"Yes",yes);
Button no(Point(140, 20),35,30,"No",no);
quit.attach(conf);
quit.attach(yes);
quit.attach(no);
wait_for_main_window_click();
}问题是,当我单击no按钮时,它会进入void no,但我不能从那里转到任何地方。我只想做quit.hide(),但是no函数看不到quit窗口(超出作用域)。我应该如何继续?谢谢
附言:我想过使用一个指针指向退出窗口,然后在no函数中使用指针退出窗口,但不确定如何准确地做到这一点。
发布于 2011-11-15 14:44:06
您可能需要考虑使用模式(即对话框)窗口。看看<FL/fl_ask.h>
if (fl_ask("Do you really want to save and exit?"))
save_and_exit();标题还具有弹出窗口的字体、标题等功能。
发布于 2012-08-10 08:25:28
当尝试关闭窗口时,将调用Fl_Window回调。默认回调隐藏窗口(如果所有窗口都被隐藏,则应用程序结束)。如果您设置了自己的窗口回调,则可以覆盖此行为,以免隐藏窗口:
// This window callback allows the user to save & exit, don't save, or cancel.
static void window_cb (Fl_Widget *widget, void *)
{
Fl_Window *window = (Fl_Window *)widget;
// fl_choice presents a modal dialog window with up to three choices.
int result = fl_choice("Do you want to save before quitting?",
"Don't Save", // 0
"Save", // 1
"Cancel" // 2
);
if (result == 0) { // Close without saving
window->hide();
} else if (result == 1) { // Save and close
save();
window->hide();
} else if (result == 2) { // Cancel / don't close
// don't do anything
}
}在设置Fl_Window的任何地方设置窗口的回调,例如在main函数中:
window->callback( win_cb );发布于 2011-11-15 14:57:53
当你构建的时候,你没有得到一个错误或者警告吗?问题可能是您有两个名为yes和no的全局函数,以及名为相同的局部变量。重命名变量的任一函数。
https://stackoverflow.com/questions/8131510
复制相似问题