Board index » delphi » Can I detect Windows shutdown request?

Can I detect Windows shutdown request?

Hi,

I wish to perform some actions when the user quits the program (namely
pop up a form) and I have hooked into  OnCloseQuery to ensure that
this happens.  

However, I do NOT want this to happen when the user is shutting down
windows - I jusrt want the program to quit straight away.

Is it possible for me to detect if the program is closing because of a
user request winthin the program as oppes to when they are shutting
down windows?

Many thanks in advance,

Greg.

 

Re:Can I detect Windows shutdown request?


coust...@netspace.net.au D?? ???
<339616e1.3988...@news.netspace.net.au>...

Quote
> I wish to perform some actions when the user quits the program (namely
> pop up a form) and I have hooked into  OnCloseQuery to ensure that
> this happens.  
> However, I do NOT want this to happen when the user is shutting down
> windows - I jusrt want the program to quit straight away.

That's known bug in Delphi 1.0 VCL, use this method:

    function WindowHook(var Message: TMessage): Boolean;

.FormCreate(Sender: TObject);
  Application.HookMainWindow(WindowHook);

.WindowHook;
begin
  Result := False;

  with Message do
    case Msg of
      WM_ENDSESSION:
        if TWMEndSession(Message).EndSession then
          Halt{FROM: hallv...@falcon.no (Hallvard Vassbotn)};

--
Alexander Petrosyan, Moscow.
email: p...@i-connect.ru, p...@fbit.msk.su
phone: +7(095)535-2222

Re:Can I detect Windows shutdown request?


Quote
> I wish to perform some actions when the user quits the program (namely
> pop up a form) and I have hooked into  OnCloseQuery to ensure that
> this happens.  

> However, I do NOT want this to happen when the user is shutting down
> windows - I jusrt want the program to quit straight away.

> Is it possible for me to detect if the program is closing because of a
> user request winthin the program as oppes to when they are shutting
> down windows?

Trap the following message, and skip the Form.CloseQuery code if it is
received before Form.CloseQuery is called...

WM_QUERYENDSESSION

The WM_QUERYENDSESSION message is sent when the user chooses to end the
Windows session, or when an application calls the ExitWindows function. If
any application returns zero, the Windows session is not ended. Windows
stops sending WM_QUERYENDSESSION messages as soon as one application
returns zero and sends WM_ENDSESSION messages, with the wParam parameter
set to FALSE, to any applications that have already returned nonzero.

--
-----------------------
Eric Lawrence
Delta Programming Group
Delta...@juno.com

Re:Can I detect Windows shutdown request?


Quote
Eric Lawrence wrote:

> > I wish to perform some actions when the user quits the program (namely
> > pop up a form) and I have hooked into  OnCloseQuery to ensure that
> > this happens.

> > However, I do NOT want this to happen when the user is shutting down
> > windows - I jusrt want the program to quit straight away.

> > Is it possible for me to detect if the program is closing because of a
> > user request winthin the program as oppes to when they are shutting
> > down windows?

> Trap the following message, and skip the Form.CloseQuery code if it is
> received before Form.CloseQuery is called...

> WM_QUERYENDSESSION

> The WM_QUERYENDSESSION message is sent when the user chooses to end the
> Windows session, or when an application calls the ExitWindows function. If
> any application returns zero, the Windows session is not ended. Windows
> stops sending WM_QUERYENDSESSION messages as soon as one application
> returns zero and sends WM_ENDSESSION messages, with the wParam parameter
> set to FALSE, to any applications that have already returned nonzero.

> --
> -----------------------
> Eric Lawrence
> Delta Programming Group
> Delta...@juno.com

bcv

Other Threads