Board index » delphi » Detecting Windows shutdown

Detecting Windows shutdown

How can I detect that my app. is being closed because Windows is being
shut down *before* the OnCloseQuery event is called?

I want to pop up an "Are you sure?" dialog is the user closes the app.
itself but not if the user is closing down to go home.

I'm using Delphi 1.0 and a mixture of Win 3.11/Win95 and Win98

Thanks in advance.

Ed.

--
Ed Weatherup
I.T. & Administration Manager

CHATER ALLAN
phone: +44 (0)1223 354233
fax: +44 (0)1223 460702

 

Re:Detecting Windows shutdown


The OnCloseQuery IS the place to do this check. Perform your checking in the
event stub with a dialog &
if the user replies that they DONT want to close the window, then raise an
exception, e.g. -
raise eAbort.Create();
and then the window will not be closed.

The OnCloseQuery event is just that, it Queries if the window can Close.
The OnClose event is called when the window actually closes, and then it is
too late to stop it.

Quote
Ed Weatherup wrote in message <360136AA.2...@ChaterAllan.co.uk>...
>How can I detect that my app. is being closed because Windows is being
>shut down *before* the OnCloseQuery event is called?

>I want to pop up an "Are you sure?" dialog is the user closes the app.
>itself but not if the user is closing down to go home.

>I'm using Delphi 1.0 and a mixture of Win 3.11/Win95 and Win98

>Thanks in advance.

>Ed.

>--
>Ed Weatherup
>I.T. & Administration Manager

>CHATER ALLAN
>phone: +44 (0)1223 354233
>fax: +44 (0)1223 460702

Re:Detecting Windows shutdown


this might work ??

put the folliwing in the Private section of your TForm1

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

this is the procedure, if called then an outside source closed your program
and not the user

procedure TForm1.WMQueryEndSession(var M:TWMQueryEndSession);
  begin
    Showmessage('windows closed me');
  Inherited
end;

--
remove .nospam if you reply by e-mail
--
The Motherboard Monitor:
http://www.euronet.nl/users/darkside/mbmonitor/
--

Quote
Ed Weatherup wrote in message <360136AA.2...@ChaterAllan.co.uk>...
>How can I detect that my app. is being closed because Windows is being
>shut down *before* the OnCloseQuery event is called?

>I want to pop up an "Are you sure?" dialog is the user closes the app.
>itself but not if the user is closing down to go home.

>I'm using Delphi 1.0 and a mixture of Win 3.11/Win95 and Win98

>Thanks in advance.

>Ed.

>--
>Ed Weatherup
>I.T. & Administration Manager

>CHATER ALLAN
>phone: +44 (0)1223 354233
>fax: +44 (0)1223 460702

Re:Detecting Windows shutdown


Thanks for the help, but I didn't make myself clear -

I *don't* want the dialog to appear when Windows is closing down, only
if the user clicks the close button.

It's a network messaging app. and I don't want the user accidentally
cutting themselves off from messages but I also don't want a dialog box
{*word*154} up the close down when, at the end of teh day, the user shuts
down Windows and walks away.

But thanks anyway.

Ed.

Quote
Dave Derrick wrote:

> The OnCloseQuery IS the place to do this check. Perform your checking in the
> event stub with a dialog &
> if the user replies that they DONT want to close the window, then raise an
> exception, e.g. -
> raise eAbort.Create();
> and then the window will not be closed.

> The OnCloseQuery event is just that, it Queries if the window can Close.
> The OnClose event is called when the window actually closes, and then it is
> too late to stop it.

> Ed Weatherup wrote in message <360136AA.2...@ChaterAllan.co.uk>...
> >How can I detect that my app. is being closed because Windows is being
> >shut down *before* the OnCloseQuery event is called?

> >I want to pop up an "Are you sure?" dialog is the user closes the app.
> >itself but not if the user is closing down to go home.

> >I'm using Delphi 1.0 and a mixture of Win 3.11/Win95 and Win98

> >Thanks in advance.

> >Ed.

> >--
> >Ed Weatherup
> >I.T. & Administration Manager

> >CHATER ALLAN
> >phone: +44 (0)1223 354233
> >fax: +44 (0)1223 460702

--
Ed Weatherup
I.T. & Administration Manager

CHATER ALLAN
phone: +44 (0)1223 354233
fax: +44 (0)1223 460702

Re:Detecting Windows shutdown


Alex,

Thanks very much - it works perfectly!!

Ed.

Quote
Alex van Kaam wrote:

> this might work ??

> put the folliwing in the Private section of your TForm1

> procedure WMQueryEndSession(var M:TWMQueryEndSession); message
> WM_QueryEndSession;

> this is the procedure, if called then an outside source closed your program
> and not the user

> procedure TForm1.WMQueryEndSession(var M:TWMQueryEndSession);
>   begin
>     Showmessage('windows closed me');
>   Inherited
> end;

> --
> remove .nospam if you reply by e-mail
> --
> The Motherboard Monitor:
> http://www.euronet.nl/users/darkside/mbmonitor/
> --
> Ed Weatherup wrote in message <360136AA.2...@ChaterAllan.co.uk>...
> >How can I detect that my app. is being closed because Windows is being
> >shut down *before* the OnCloseQuery event is called?

> >I want to pop up an "Are you sure?" dialog is the user closes the app.
> >itself but not if the user is closing down to go home.

> >I'm using Delphi 1.0 and a mixture of Win 3.11/Win95 and Win98

> >Thanks in advance.

> >Ed.

--
Ed Weatherup
I.T. & Administration Manager

CHATER ALLAN
phone: +44 (0)1223 354233
fax: +44 (0)1223 460702

Other Threads