I'm trying to catch the windows shutdown message in my application so
that when a user selects Start->Shutdown my application can terminate
itself gracefully. I know this is possible because Microsoft
applications do this (could this be yet another example of Microsoft
using undocumented features of their OS in their applications). I've
tried setting up handlers for the Term and Abort signals using signal()
but this did not help. Any suggestions would be appreciated.
Thanks,
Jeremy Kaufman
However, the jist of it is that you need to catch the WM_QUERYENDSESSION and
WM_ENDSESISON messages, both of which are documented in the Win32 API
reference (win32.hlp) that came with BCB
Gambit
"Jeremy Kaufman" <jlka...@home.com> wrote in message
news:3A131C80...@home.com...
Trap WM_QUERYENDSESSION
Richard Kable wrote:
>
> "Jeremy Kaufman" <jlka...@home.com> wrote in message
> news:3A131C80...@home.com...
> > Hi,
> >
> > I'm trying to catch the windows shutdown message in my application so
> > that when a user selects Start->Shutdown my application can terminate
> > itself gracefully. I know this is possible because Microsoft
> > applications do this (could this be yet another example of Microsoft
> > using undocumented features of their OS in their applications). I've
> > tried setting up handlers for the Term and Abort signals using signal()
> > but this did not help. Any suggestions would be appreciated.
> >
> > Thanks,
> > Jeremy Kaufman
>
> Jeremy,
> This question would be better off being posted to the
> borland.public.cppbuilder.winapi newsgroup.
> However I can say that the solution lies in capturing the Win32
> WM_QUERYENDSESSION message that is sent to all applications before Windows
> can shut down. You would need to add WM_QUERYENDSESSION to a MESSAGE_MAP to
> be able to detect and handle it. For more info look up WM_QUERYENDSESSION in
> the help file.
>
> HTH.
> --
> Richard Kable
> Source Communications
> Melbourne, Australia
The catch (at least with BCB5) is that WM_QUERYENDSESSION gets sent to the
forms, not to the main Application->OnMessage event.
--
Lucian
This is because the Application->OnMessage event only captures posted
messages, not sent messages.
To capture messages sent to the main window (such as WM_QUERYENDSESSION)you
can use the Application->HookMainWindow method instead. HookMainWindow is a
very powerful but under-rated mechanism - largely because Borland's
documentation "suggests" that it's only usable with "non-VCL dialog box"
message handling. In fact HookMainWindow is one of the few ways that allows
you to trap the WM_ENDSESSION message to prevent Win9x service applications
from closing when a user logs out [as MESSAGE_MAPs don't work with
WM_ENDSESSION].
Cheers,
Right. What I meant to say was "the catch is that WM_QUERYENDSESSION doesn't
get sent to the application main window, as was expected by the
VCL-programmers. Therefore, the elaborate scheme of shutdown behaviour that
they crafted in response to the message, simply gets ignored."
--
Lucian