如何判断用户是否试图用C++关闭窗口

How can I tell if the user tries to close the window in C++?

本文关键字:C++ 窗口 是否 何判断 判断 用户      更新时间:2023-10-16

当用户单击窗口上的关闭按钮时,我需要中断while循环,但我不知道该检查什么。我正在使用allegro来运行GUI。

如果使用Allegro 4:set_close_button_callback()

volatile int hit_closed = 0;
void close_button_proc()
{
  hit_closed = 1;
}
// later after creating the display:
set_close_button_callback(close_button_proc);
while (!hit_closed)
{
}

对于Allegro 5,它更像是:

al_register_event_source(queue, al_get_display_event_source(display));
// in your event loop:
if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
}

有关所有详细信息,请参阅手册。