如何判断用户是否尝试在C++中关闭窗口?

Joh*_*mac 6 c++ allegro

当用户点击窗口上的关闭按钮时,我需要打破一个while循环,但我不知道要检查什么.我正在使用allegro来运行GUI.

Mat*_*hew 1

如果使用 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)
{
}
Run Code Online (Sandbox Code Playgroud)

对于 Allegro 5,它更像是:

al_register_event_source(queue, al_get_display_event_source(display));

// in your event loop:

if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
}
Run Code Online (Sandbox Code Playgroud)

请参阅手册了解所有详细信息。