Board index » delphi » Detecting Windows Shutdown??

Detecting Windows Shutdown??

I'm trying to figure out how to detect  Windows 95 shutdown from within
a Delphi 2.0 application, for example, from within the OnCloseQuery
event handler.  Unlike Visual Basic, Delphi's OnCloseQuery handler does
not pass a parameter reporting the cause of the close form event, e.g.,
to distinguish between a form closing prompted by user clicking on a
system menu vs. shutdown of a Windows session.  Does one have to write
an event handler to detect the WM_ENDSESSION message or some similar
message?  Your suggestions would be appreciated.

--
Roger C. Spaeder [spae...@ix.netcom.com] {*word*269}ia

 

Re:Detecting Windows Shutdown??


"Roger C. Spaeder" <spae...@ix.netcom.com> wrote:

Quote
>I'm trying to figure out how to detect  Windows 95 shutdown from within
>a Delphi 2.0 application, for example, from within the OnCloseQuery
>event handler.  Unlike Visual Basic, Delphi's OnCloseQuery handler does
>not pass a parameter reporting the cause of the close form event, e.g.,
>to distinguish between a form closing prompted by user clicking on a
>system menu vs. shutdown of a Windows session.  Does one have to write
>an event handler to detect the WM_ENDSESSION message or some similar
>message?  Your suggestions would be appreciated.

You must do a lot to detect this.
You have to Hook the MainWindow from your application. There is a
function to do this "HookMainWindow". Look up this function in the
help to figure out, what to pass. Then you can intercept the
WM_ENDSESSION message correctly and do any cleanup you need. Make sure
you set the flags in a way that delphi does not handle this message by
default, as it calls an immediate "Halt" and your application will go
away....

Hope this helps
Meik Weber
m.we...@public.ndh.com or
100744.3...@compuserve.com

Re:Detecting Windows Shutdown??


To the person wanting to re-start Windows...

   ExitWindows(EW_RESTARTWINDOWS, 0)

Make sure you _don't_ try this while you're in the IDE.
Instant hang...after you compile, it works like a champ...

There's also another API function called ExitWindowsExec
that'll kick you out of Windows to the DOS prompt.

JE McTaggart
t...@iguana.ruralnet.net

Re:Detecting Windows Shutdown??


Hallo,

Quote
Mein Weber wrote:
>"Roger C. Spaeder" <spae...@ix.netcom.com> wrote:

>>I'm trying to figure out how to detect  Windows 95 shutdown from within
>>a Delphi 2.0 application, for example, from within the OnCloseQuery
>>event handler.  Unlike Visual Basic, Delphi's OnCloseQuery handler does
>>not pass a parameter reporting the cause of the close form event, e.g.,
>>to distinguish between a form closing prompted by user clicking on a
>>system menu vs. shutdown of a Windows session.  Does one have to write
>>an event handler to detect the WM_ENDSESSION message or some similar
>>message?  Your suggestions would be appreciated.

>You must do a lot to detect this.
>You have to Hook the MainWindow from your application. There is a
>function to do this "HookMainWindow". Look up this function in the
>help to figure out, what to pass. Then you can intercept the
>WM_ENDSESSION message correctly and do any cleanup you need. Make sure
>you set the flags in a way that delphi does not handle this message by
>default, as it calls an immediate "Halt" and your application will go
>away....

Could someone post some source demonstrating how to do this ?

        Mls, Kay

--
**********************************
* k...@edition.bonbit.org         *
* gamemas...@edition.bonbit.org  *
* Telefon: 0431/64526            *
**********************************

Other Threads