I have written a program in C++ and before exit I store some data in files. However, if the user clicks on the close box (X) on top right corner I lose those data. Is there a way to detect if the user clicks on the close box, so that I call some functions before exit?
Asked
Active
Viewed 122 times
1 Answers
2
Use SetConsoleCtrlHandler() to installer a handler that looks for the CTRL_CLOSE_EVENT event:
A signal that the system sends to all processes attached to a console when the user closes the console (either by clicking Close on the console window's window menu, or by clicking the End Task button command from Task Manager).
Remy Lebeau
- 505,946
- 29
- 409
- 696