- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


3133:Detecting Windows Shutdown

KEYWORDS: detecting shutdown EndSession WM_QueryEndSession ExitWindows AREA: I

It is possible for you to detect when windows is being shutdown and
to prevent this shutdown from within a running Delphi application.

The simple solution is to add an event handler to the main form's
OnCloseQuery event. This event handler occurs as a result of a
WM_QUERYENDSESSION message which is sent to all running application
in Windows when Windows is about to be shut down.  The boolean
CanClose parameter to this event can be set to True to allow Windows
to shut down or, CanClose can be set to False to prevent Windows
from shutting down.

The code below illustrates using this event.

----- Code Follows -------

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  // Ask user if shutdown should occur.
  if MessageDlg('Are you sure?', mtConfirmation, mbYesNoCancel, 0) = mrYes
  then CanClose := true    // Allow Windows to shut down.
  else CanClose := false;  // Prevent Windows from shutting down.
end;


        TI



* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile