Tuesday, February 14, 2006

Detecting Windows shutdown

When Windows is shutting down, it sends a WM_QueryEndSession to all open applications. To detect (and prevent shutdown), you must define a message handler to this message. Put this definition on the private section of the main form:




    procedure WMQueryEndSession(var Msg : TWMQueryEndSession); message WM_QueryEndSession;

And put this method in the implementation section of the unit:


    procedure TForm1.WMQueryEndSession(var Msg : TWMQueryEndSession);

    begin

      if MessageDlg('Close Windows ?', mtConfirmation, [mbYes,mbNo], 0) = mrNo then

        Msg.Result := 0

      else

        Msg.Result := 1;

    end;

0 Comments:

Post a Comment

<< Home