Board index » delphi » Detecting Windows Shutdown in FormCloseQuery

Detecting Windows Shutdown in FormCloseQuery

In the FormCloseQuery event, how can I detect if it is because of user
action or due to windows shutdown...

Cesare

 

Re:Detecting Windows Shutdown in FormCloseQuery


procedure TForm1.WMSYSCOMMAND(var Message: TMessage);
Begin
  if (Message.WParam and $FFF0) = SC_CLOSE then eigenclose:=True;
  inherited;
End;

Cesare <ces...@digitalmail.nospam.com> schreef in berichtnieuws
3a6c30a8_2@dnews...

Quote
> In the FormCloseQuery event, how can I detect if it is because of user
> action or due to windows shutdown...

> Cesare

Re:Detecting Windows Shutdown in FormCloseQuery


"Alan Beaudoin" <abeaud...@winspc.com> skrev i en meddelelse
news:tlnt6t8f5jjnvgqh5h13qmc4dqr7uufel5@4ax.com...

Quote
> To detect a Windows shutdown, you should write a message handler for
> WM_QUERYENDSESSION.

It should WM_ENDSESSION.

The WM_QUERYENDSESSION message does not nescessarily mean that windows will
shut down.

Finn Tolderlund

Re:Detecting Windows Shutdown in FormCloseQuery


I'm having real trouble with this. I compile my app and run it as an exe,
but when I try to restart windows it pulls up Delphi with a blank project
and asks if I want to save changes, whatever I select the shutdown is
cancelled and when I go back into Delphi the delphi32.dsk has been trashed
and I can't get to any of the forms. I really don't have a clue what's
happening. Is there anyway to debug this or do you have any examples...

here's what I've got...

protected
    procedure WindowsShutdown(var Message: TMessage);

...

...

procedure TFmCass.WindowsShutdown(var Message: TMessage);
begin
    StopExecute(Self);
    Self.Close;
    inherited;
end;

I have tried several combinations of code in the procedure but nothing seems
to work.

Any further help would be really appreciated.

Cesare

"Finn Tolderlund" <XnospamYfinn.tolderlu...@Ymobilixnet.dkXnospamY> wrote in
message news:3a6c6480$1_2@dnews...

Quote

> "Alan Beaudoin" <abeaud...@winspc.com> skrev i en meddelelse
> news:tlnt6t8f5jjnvgqh5h13qmc4dqr7uufel5@4ax.com...
> > To detect a Windows shutdown, you should write a message handler for
> > WM_QUERYENDSESSION.

> It should WM_ENDSESSION.

> The WM_QUERYENDSESSION message does not nescessarily mean that windows
will
> shut down.

> Finn Tolderlund

Re:Detecting Windows Shutdown in FormCloseQuery


"Cesare" <ces...@digitalmail.nospam.com> skrev i en meddelelse
news:3a6c7483_2@dnews...

Quote
> do you have any examples...

  private
    { Private declarations }
    procedure WMENDSESSION(var Msg: TMessage); message WM_ENDSESSION;

implementation

procedure TForm1.WMENDSESSION(var Msg: TMessage);
begin
// Windows is now shutting down
end;

Finn Tolderlund

Re:Detecting Windows Shutdown in FormCloseQuery


Sorry to be a pain...

Although I'm writing this as a normal app, it is a service of kinds which
you can start and stop. When it is running the FormCloseQuery asks if you
are sure you wish to exit, obviously I would like to bypass this when it is
due to Windows Shutdown.
I have now realised what is happening. The FormCloseQuery Event is firing
before the WM_ENDSESSION code, which kind of defeats the point of having it.

Any further ideas would be greatly appreciated...

Cesare

"Finn Tolderlund" <XnospamYfinn.tolderlu...@Ymobilixnet.dkXnospamY> wrote in
message news:3a6c99a3_1@dnews...

Quote

> "Cesare" <ces...@digitalmail.nospam.com> skrev i en meddelelse
> news:3a6c7483_2@dnews...
> > do you have any examples...

>   private
>     { Private declarations }
>     procedure WMENDSESSION(var Msg: TMessage); message WM_ENDSESSION;

> implementation

> procedure TForm1.WMENDSESSION(var Msg: TMessage);
> begin
> // Windows is now shutting down
> end;

> Finn Tolderlund

Re:Detecting Windows Shutdown in FormCloseQuery


thank you v much for your help. I had to revert to using WM_QUERYENDSESSION
so that I could get the message before the FormCloseQuery, but as a
consequence can also cancel the shutdown under certain circumstances, which
is even better than my original plan!

Thanks

Cesare

Quote
"Cesare" <ces...@digitalmail.nospam.com> wrote in message

news:3a6d651b_1@dnews...
Quote
> Sorry to be a pain...

> Although I'm writing this as a normal app, it is a service of kinds which
> you can start and stop. When it is running the FormCloseQuery asks if you
> are sure you wish to exit, obviously I would like to bypass this when it
is
> due to Windows Shutdown.

> I have now realised what is happening. The FormCloseQuery Event is firing
> before the WM_ENDSESSION code, which kind of defeats the point of having
it.

> Any further ideas would be greatly appreciated...

> Cesare

> "Finn Tolderlund" <XnospamYfinn.tolderlu...@Ymobilixnet.dkXnospamY> wrote
in
> message news:3a6c99a3_1@dnews...

> > "Cesare" <ces...@digitalmail.nospam.com> skrev i en meddelelse
> > news:3a6c7483_2@dnews...
> > > do you have any examples...

> >   private
> >     { Private declarations }
> >     procedure WMENDSESSION(var Msg: TMessage); message WM_ENDSESSION;

> > implementation

> > procedure TForm1.WMENDSESSION(var Msg: TMessage);
> > begin
> > // Windows is now shutting down
> > end;

> > Finn Tolderlund

Re:Detecting Windows Shutdown in FormCloseQuery


You must respond to WM_QUERYENDSESSION to get notification of imminent
shutdown, and to WM_ENDSESSION to respond to the actual shutdown. Return
TRUE to WM_QUERYENDSESSION if it's OK to end; if you return FALSE the
system will *not* shut down.

Just to be nice, Bill Gates made the Win9x and WinNT-family work
differently here. Under Win9x, if ALL programs return True to
WM_QUERYENDSESSION, then they all receive WM_ENDSESSION and terminate.
Under WinNT-family, if your program returned True to the QUERY, it gets
terminated regardless of other programs.

--
Neil J. Rubenking
Contributing Technical Editor
PC Magazine

Other Threads