Board index » delphi » Closing my app automatically when Windows closes (2)

Closing my app automatically when Windows closes (2)

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 (2)


Did you return a true to the WM_QUERYENDSESSION mesage?

A false (0) response will stop Windo$e trying to shut down.

On Thu, 15 Nov 2001 17:52:40 +0100, "Jimmy Rasmussen"

Quote
<Jim...@get2net.dk> wrote:
>WM_QUERYENDSESSION

Re:Closing my app automatically when Windows closes (2)


I've been doing something similar:
I have overridden the wndproc procdure for the main form so if the windows
message is WM_QUERYENDSESSION I set a flag(say MyCloseFlag), that is set to
false in the FormCreate procedure, to true then call the inherited wndproc
procedure to actually handle the message. e.g

procedure TMyForm.WndProc(var Message: TMessage);
begin
if (Message.Msg=WM_QUERYENDSESSION) then
  MyCloseFlag:=true;
inherited WndProc(Message);
end;

in the FormCloseQuery procedure, have something like
CanClose:=MyCloseFlag;

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

news:3bf3f305$0$4862$ba624c82@nntp02.dk.telia.net...
Quote
> 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 (2)


Use the abovely commented WM_QUERYENDSESSION
to set canclose to true

Other Threads