System is about to enter a sleep/hibernation mode, or is shutting down.
This message is received by the screen window when the user activates the sleep mode option (by pressing the power button, pushing the kbSleep key, closing the notebook cover, rtc.), or shuts down or reboots the computer. The computer can also suspend itself automatically, if it was idle for a certain period of time, or if the battery is running out. This message cannot be generated programmatically.
The suspension process is paused while the app is processing this message, but only for a brief period (a few seconds). If OnSystemSuspending takes too much time to complete, the system may proceed with suspension anyway, even if it means closing this app by force. Therefore, OnSystemSuspending should return quickly. In particular, it should not open a user dialog. The app cannot prevent the suspension of the system.
- This message is needed for safety and reliability. The app can use it to stop and/or finalize some lengthy operation, such as file copying. Of course, any app should be designed in such a way that it can ignore (or easily recover from) a sudden shutdown. In particular, files should be open only as necessary, and closed as soon as possible; unsaved data should be frequently stored in a temporary file (see Example); and so on
- The message is not received if the system shuts down unexpectedly, e.g. due to a power failure, or because the user pressed the "Reset" button on the computer. All the more reason to make the app "suspension-proof" as described above
- If this message is received due to shutdown, the app is terminated by the system shortly after this message is processed (there is no need to terminate the app manually)
- An app that wants to process this message has to propagate it from the screen to one of its windows by calling requestPropagation(mcSystemSuspending,psScreen) (MMainFrame constructor does this by default), because the screen does not handle this message
- ON_SystemSuspending macro should be used instead of defining the handler overload manually (see ON_XXXX)
Let us know
Please Contact us to report any errors on this page, or to suggest any improvements.