FLTK 关闭窗口
我正在使用 FLTK。我有一个带有各种按钮的窗口,用户可以单击来执行某些操作。在我的 int main() 中,我有一个 switch 语句来处理所有这些。当用户单击 exit 时, switch 语句的设置如下:
case Exit_program:
cout << "save files and exit\n";
do_save_exit(sw);
这将转到 do_save_exit 函数,该函数创建一个退出确认窗口,其中包含两个按钮 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();
}
问题是,当我单击“否”按钮时,它会变为“无效”,但我无法从那里去任何地方。我只想执行 quit.hide() 但 no 函数看不到退出窗口(超出范围)。我应该如何进行?谢谢
PS:我曾考虑过使用指向退出窗口的指针,然后使用该指针在 no 函数中退出窗口,但不确定具体如何执行。
I am using FLTK. I have a window with a variety of buttons the user can click to perform some action. In my int main() i have a switch statement to handle all of these. When the user clicks exit the switch statement is setup like so:
case Exit_program:
cout << "save files and exit\n";
do_save_exit(sw);
This goes to the do_save_exit function that creates a exit confirmation window with two buttons yes (exit) and no (don't exit). I got the yes button to work, exits the program, but the no button mean i should just hide the confirmation window. This is the follow functions:
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();
}
The problem is, when i click the no button it goes to void no, but I can't go anywhere from there. I just want to do quit.hide() but the no function doesn't have sight of the quit window (out of scope). How should I proceed? Thank you
P.S: I have thought about using a pointer to the quit window and then using the pointer to quit the window in the no function but am not sure how to do that exactly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当尝试关闭窗口时,将调用 Fl_Window 回调。默认回调隐藏窗口(如果所有窗口都隐藏,则应用程序结束)。如果您设置自己的窗口回调,则可以覆盖此行为,以免隐藏窗口:
在设置 Fl_Window 的任何位置设置窗口的回调,例如在 main 中> 功能:
The Fl_Window callback is called when an attempt is made to close the window. The default callback hides the window (and if all windows are hidden, your application ends). If you set your own window callback, you can override this behaviour, so as not to hide the window:
Set your window's callback wherever you set up your Fl_Window, e.g. in your main function:
您可能需要考虑使用模式(即对话框)窗口。看
标头还具有弹出窗口的字体、标题等功能。
You probably need to look at using a modal (i.e., dialog) window. Look at
<FL/fl_ask.h>
The header also has functions for the popup's font, title, etc.
当您构建时,您没有收到错误或警告吗?问题可能是您既有全局函数名称
yes
和no
,也有名称相同的局部变量。重命名变量的函数。When you build you don't get an error or warning? The problem is probably that you have both global functions names
yes
andno
and also local variables called just the same. Rename either the functions of the variables.无需使用 hide()。
您只需在回调中使用
exit(0);
即可。No need to use hide().
You can simply use
exit(0);
in a callback.