Board index » delphi » Closing my app automatically when Windows closes

Closing my app automatically when Windows closes

I've build an app that resides in the windows taskbar. When one tries to
shut down windows, nothing happens, unless one shuts down the app first !

How do I avoid this problem ? Is it possible to detect that windows is
shutting down ?

regards

Jimmy

 

Re:Closing my app automatically when Windows closes


Your program should be quitting when windows shuts down, but if you want to
you can handle the message

WM_QUERYENDSESSION

which is sent to the applications main window..

Quote
"Jimmy Rasmussen" <Jim...@get2net.dk> wrote in message

news:3bf17007$0$11604$ba624c82@nntp01.dk.telia.net...
Quote
> I've build an app that resides in the windows taskbar. When one tries to
> shut down windows, nothing happens, unless one shuts down the app first !

> How do I avoid this problem ? Is it possible to detect that windows is
> shutting down ?

> regards

> Jimmy

Re:Closing my app automatically when Windows closes


Quote
"Jimmy Rasmussen" <Jim...@get2net.dk> wrote in message

news:3bf17007$0$11604$ba624c82@nntp01.dk.telia.net...

Quote
> I've build an app that resides in the windows taskbar. When one tries to
> shut down windows, nothing happens, unless one shuts down the app first !

> How do I avoid this problem ? Is it possible to detect that windows is
> shutting down ?

> regards

> Jimmy

You can use an OnCloseQuery event exit to do any cleanup required and then
setting CanClose to true.    This is the default action though - by default
your program should shutdown when windows requests it to.  Are you saying
that it does not?

________________________
Gary
http://www.delphiforfun.org
_________________________

Re:Closing my app automatically when Windows closes


And how to do this, if no real Window existst?

Re:Closing my app automatically when Windows closes


I think the source of my problems lies in my FormCloseQuery statement:

FormCloseQuery
begin
        CanClose := False;
        Form1.Hide;
end;

I've written this to avoid the application from closing when the main form
is being closed by the user. I've tried using the message WM_QUERYENDSESSION
recommended by Mathew and terminating the application when the mesage
arrives, but although the application did terminate, I had to press shut
down twice to shut down windows. So I guess I need to revise the CloseQuery
procedure to get rid of this problem, any suggestions ?

regards

Jimmy

Re:Closing my app automatically when Windows closes


I think the source of my problems lies in my FormCloseQuery statement:

FormCloseQuery
begin
        CanClose := False;
        Form1.Hide;
end;

I've written this to avoid the application from closing when the main form
is being closed by the user, but unfortunately Windows won't shut down while
my app is open. So I need to detect when Windows tries to shut down, and
then automatically close my app. I've tried using the message
WM_QUERYENDSESSION recommended by Mathew and terminating the application
when the mesage arrives, but although the application did terminate, I had
to press shut down twice to shut down windows. So I guess I need to revise
the CloseQuery procedure to get rid of this problem, any suggestions ?

regards

Jimmy

Re:Closing my app automatically when Windows closes


Quote
Jimmy Rasmussen wrote:

> I think the source of my problems lies in my FormCloseQuery statement:

> FormCloseQuery
> begin

    { InSendMessage returns true if message came from outside of app
      false if message came from app          }
    if InSendMessage then CanClose := true
    else begin
Quote
>         CanClose := False;
>         Form1.Hide;
    end;
> end;

Other Threads