Board index » delphi » Detecting Windows Shutdown when assigning a procedure to OnCloseQuery

Detecting Windows Shutdown when assigning a procedure to OnCloseQuery

I have written a program that minimizes itself to the system tray when the
(X) Close icon is clicked. I have written a handler for OnCloseQuery in the
main form that sets CanClose to false and then calls my
TrayIcon.HideApplication (hides the window and then puts in a trayicon).

However, when the system shuts down, my application keeps running and I have
to terminate the PROCESS using the Task Manager.

I know that this is caused by the OnCloseQuery handler that sets CanClose to
false. I need a way to detect the Windows shutdown.

Can anyone help?

Best Regards,

Tom Reiertsen.

 

Re:Detecting Windows Shutdown when assigning a procedure to OnCloseQuery


{private}
procedure WMQUERYENDSESSION(var Msg: TMessage); message
WM_QUERYENDSESSION;

const
  bCanClose : boolean = false;

procedure TForm1.WMQUERYENDSESSION(var Msg: TMessage);
begin
  bCanClose := true;
  inherited;
end;

// In OnCloseQuery:
  if bCanClose then CanClose := true
  else.....

Quote
Tom Reiertsen wrote:

> However, when the system shuts down, my application keeps running and I have
> to terminate the PROCESS using the Task Manager.

> I know that this is caused by the OnCloseQuery handler that sets CanClose to
> false. I need a way to detect the Windows shutdown.

Re:Detecting Windows Shutdown when assigning a procedure to OnCloseQuery


Thank you. It worked out perfectly.

Best Regards,

Tom Reiertsen.

Re:Detecting Windows Shutdown when assigning a procedure to OnCloseQuery


Quote
Tom Reiertsen wrote:

> I know that this is caused by the OnCloseQuery handler that sets CanClose to
> false. I need a way to detect the Windows shutdown.

> Can anyone help?

A little more simple approach then Chris' method:

In OnCloseQuery event:

  CanClose := InSendMessage;

(InSendMessage tells you if event is triggered from outside your app.)

-- Erwin Dokter
   mailto:edok...@home.nl
   http://members.home.nl/edokter

Re:Detecting Windows Shutdown when assigning a procedure to OnCloseQuery


I cannot find any documentation on InSendMessage.
where is it ?

--
Poirazis Michael

Quote
"Erwin Dokter" <edok...@home.nl> wrote in message

news:3ADD9730.4920@home.nl...
Quote
> Tom Reiertsen wrote:

> > I know that this is caused by the OnCloseQuery handler that sets
CanClose to
> > false. I need a way to detect the Windows shutdown.

> > Can anyone help?

> A little more simple approach then Chris' method:

> In OnCloseQuery event:

>   CanClose := InSendMessage;

> (InSendMessage tells you if event is triggered from outside your app.)

> -- Erwin Dokter
>    mailto:edok...@home.nl
>    http://members.home.nl/edokter

Re:Detecting Windows Shutdown when assigning a procedure to OnCloseQuery


I remember seeing this answer once before but have never used it. Is
InSendMessage in D3?

Chris

Quote
Erwin Dokter wrote:
> A little more simple approach then Chris' method:
> In OnCloseQuery event:
>  CanClose := InSendMessage;
>(InSendMessage tells you if event is triggered from outside your app.)

Re:Detecting Windows Shutdown when assigning a procedure to OnCloseQuery


Quote
Chris Willig wrote:

> I remember seeing this answer once before but have never used it. Is
> InSendMessage in D3?

Yes. This function dates back to Windows 2.x(!) and is available in all
Delphi versions.

-- Erwin Dokter
   mailto:edok...@home.nl
   http://members.home.nl/edokter

Re:Detecting Windows Shutdown when assigning a procedure to OnCloseQuery


Quote
Michael Poirazi wrote:

> I cannot find any documentation on InSendMessage.
> where is it ?

It should be in Win32.hlp. The function is declared in windows.pas.

-- Erwin Dokter
   mailto:edok...@home.nl
   http://members.home.nl/edokter

Other Threads