Title: detecting/preventing shutdown for my app/windows
Question: how can i detect/prevent shutdown ?
Answer:
the following proc, declared as:
procedure WMQueryEndSession( var Message: TWMQueryEndSession); message WM_QUERYENDSESSION;
and defined as:
procedure TMainFrm.WMQueryEndSession(var Message: TWMQueryEndSession);
begin
Message.Result:=1;
gEndSession := True;
end;
is called whenever windows is about to shutdown. I have it set so that when this occurs it will do so quietly, but normally this procedure is called:
(Set this for the CloseQuery event)
procedure TMainFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose := True;
if gQueryEnd and not gEndSession then
if MessageDlg('Quitting (your app name). Are you sure?',
mtInformation, mbOKCancel, 0) = mrCancel then CanClose := False
end;
gQueryEnd is a global boolean user setting.
gEndSession is a global boolean setting to prevent the message from displaying.
gEndSession should be set before attempting to close the form.
Tested with delphi 4 and 5 on 95/98/NT4 and w2k.