C++ 关闭窗口
我正在使用FLTK。我有一个带有各种按钮的窗口,用户可以单击这些按钮执行一些操作。在我的int main()中,我有一个switch语句来处理所有这些。当用户单击退出时,开关语句的设置如下:C++ 关闭窗口,c++,user-interface,window,fltk,C++,User Interface,Window,Fltk,我正在使用FLTK。我有一个带有各种按钮的窗口,用户可以单击这些按钮执行一些操作。在我的int main()中,我有一个switch语句来处理所有这些。当用户单击退出时,开关语句的设置如下: case Exit_program: cout << "save files and exit\n"; do_save_exit(sw); 问题是,当我点击“否”按钮时,它将变为无效“否”,但我无法从那里转到任何地方。我只想执行quit.hide(),但是no函数看不到quit
case Exit_program:
cout << "save files and exit\n";
do_save_exit(sw);
问题是,当我点击“否”按钮时,它将变为无效“否”,但我无法从那里转到任何地方。我只想执行quit.hide(),但是no函数看不到quit窗口(超出范围)。我应该如何进行?多谢各位
附言:我曾经考虑过使用一个指向退出窗口的指针,然后在no函数中使用指针退出窗口,但我不知道该怎么做 您可能需要查看如何使用模式(即对话框)窗口。看看
标题还具有用于弹出窗口字体、标题等的功能。当您构建时,您不会收到错误或警告吗?问题可能是您既有全局函数名
yes
和no
,也有局部变量名相同。重命名变量的任一函数。当试图关闭窗口时,调用Fl\u窗口回调。默认回调将隐藏窗口(如果所有窗口都隐藏,则应用程序将结束)。如果设置自己的窗口回调,则可以覆盖此行为,以避免隐藏窗口:
// 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\U窗口的任何位置设置窗口的回调,例如在main函数中:
window->callback( win_cb );
不需要使用hide()。
您只需使用
exit(0)代码>在回调中。太棒了。非常感谢。把我的头发扯下来想弄清楚这个。
// 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
}
}
window->callback( win_cb );