1set_close_button_callback(3) Allegro manual set_close_button_callback(3)
2
3
4
6 set_close_button_callback - Handles the user clicking on the close but‐
7 ton of the window. Allegro game programming library.
8
10 #include <allegro.h>
11
12
13 int set_close_button_callback(void (*proc)(void));
14
16 On platforms that have a close button, this routine installs a callback
17 function to handle the close event. In other words, when the user
18 clicks the close button on your program's window or any equivalent
19 device, the function you specify here will be called.
20
21 This function should not generally attempt to exit the program or save
22 any data itself. The function could be called at any time, and there is
23 usually a risk of conflict with the main thread of the program.
24 Instead, you should set a flag during this function, and test it on a
25 regular basis in the main loop of the program.
26
27 Pass NULL as the `proc' argument to this function to disable the close
28 button functionality, which is the default state.
29
30 Note that Allegro cannot intercept the close button of a DOS box in
31 Windows.
32
33 Also note that the supplied callback is also called under MacOS X when
34 the user hits Command-Q or selects "Quit" from the application menu.
35 Example:
36
37 volatile int close_button_pressed = FALSE;
38
39 void close_button_handler(void)
40 {
41 close_button_pressed = TRUE;
42 }
43 END_OF_FUNCTION(close_button_handler)
44 ...
45
46 allegro_init();
47 LOCK_FUNCTION(close_button_handler);
48 set_close_button_callback(close_button_handler);
49 ...
50
51 while (!close_button_pressed)
52 do_stuff();
53
55 Returns zero on success and non-zero on failure (e.g. the feature is
56 not supported by the platform).
57
58
60 set_window_title(3)
61
62
63
64Allegro version 4.2.2 set_close_button_callback(3)