Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trying To Catch Windows Shutdown Message In Application

179 views
Skip to first unread message

Jeremy Kaufman

unread,
Nov 15, 2000, 3:00:00 AM11/15/00
to
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

Remy Lebeau

unread,
Nov 15, 2000, 3:00:00 AM11/15/00
to
This is not a language issue. You will get better responses in the
borland.public.cppbuilder.winapi newsgroup instead.

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...

Greg Chicares

unread,
Nov 15, 2000, 3:00:00 AM11/15/00
to
Jeremy Kaufman wrote:
>
> 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.

Trap WM_QUERYENDSESSION

Jeremy Kaufman

unread,
Nov 16, 2000, 3:00:00 AM11/16/00
to
Thanks for the help. Sorry for posting in the woring area.

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

Richard Kable

unread,
Nov 16, 2000, 9:53:49 PM11/16/00
to

Lucian Wischik

unread,
Nov 16, 2000, 10:31:46 PM11/16/00
to
> 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.

The catch (at least with BCB5) is that WM_QUERYENDSESSION gets sent to the
forms, not to the main Application->OnMessage event.

--
Lucian


Richard Kable

unread,
Nov 17, 2000, 8:36:14 PM11/17/00
to
"Lucian Wischik" <ljw...@cam.ac.uk> wrote in message
news:8v28rc$or...@bornews.inprise.com...

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,

Lucian Wischik

unread,
Nov 18, 2000, 3:00:00 AM11/18/00
to
> > The catch (at least with BCB5) is that WM_QUERYENDSESSION gets sent to
the
> > forms, not to the main Application->OnMessage event.
>
> This is because the Application->OnMessage event only captures posted
> messages, not sent messages.

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


0 new messages