Prevent a user from closes Windows
When the user closes Windows having our application opened, it is possible that occur in a wrong moment (without recording data, in the middle of a process, etc). This can be avoided capturing the message that send Windows to all the applications when the user wants to close Windows: the message WM_QUERYENSESSION
To capture the message and to send it to our treatment code of the message:
Simply...we must add the next line in the Private clausule od the form:
and later, in the implementation, we put the treatment code of the message:
If instead of aborting the close of Windows, we want that follows being accomplished, enough with which we change the Msg.result:=0 for Msg.result:=1.
NOTE: The behavior of the message defers in win98 and WinNT, as soon as watches you the help of the message WM_QUERYENDSESSION.