Board index » cppbuilder » Windows shutdown not closing my app

Windows shutdown not closing my app


2005-11-10 10:11:34 PM
cppbuilder50
I have Googled this to death, and have seen quite a bit about similar
problems, but not exactly like my situation.
I have an application (normal app, not system tray like many I saw) that
uses the OnCloseQuery handler to do some cleanup before the app terminates.
Works great when the user closes the application.
However, when Windows does a shutdown things are different. My
OnCloseQuery handler is being executed. It is setting CanClose to true.
But, Windows is not closing my app and aborts the shutdown process. This
leaves my app running, but since I did my cleanup, in an unstable state.
Why would Windows not shut down my app if I told it that it CanClose?
I am not using AllocateHWND as was suggested in many previous posts. I do
have a custom component that overrides the WndProc(), but it passes
processing of all but one message (WM_GETDLGCODE) on to TWinControl's
WndProc(). This is the only WndProc that I have overridden myself. I
tried having this WndProc() trap the WM_QUERYENDSESSION message and set the
Result to 1, but this did not help.
Any help is greatly appreciated.
Joe
 
 

Re:Windows shutdown not closing my app

Quote
tried having this WndProc() trap the
WM_QUERYENDSESSION [...]
Not only the WM_QUERYENDSESSION !
This is the code that works fine for me:
void __fastcall TDiMainForm::WndProc( TMessage &Message )
{
switch ( Message.Msg )
{
// ... other messages ...
case WM_QUERYENDSESSION:
case WM_ENDSESSION:
YourCleanUpCodeHere();
break;
// ... other messages ...
}
TForm::WndProc( Msg );
}
--
Best regards,
Vladimir Stefanovic
 

Re:Windows shutdown not closing my app

Vladimir,
Thanks for the reply. However, the WndProc() that I described was for a
custom component only. It is not for a form, let alone the main form. My
main form does not override the WndProc().
I only added the WM_QUERYENDSESSION message to the custom component's
WndProc as a test to see if that might be the problem.
A question about your code, though. Do you really want to do the cleanup
in both the WM_QUERYENDSESSION and the WM_ENDSESSION? Won't this result in
having your cleanup code execute twice?
Thanks again.
Joe
"Vladimir Stefanovic" < XXXX@XXXXX.COM >wrote in message
Quote
>tried having this WndProc() trap the
>WM_QUERYENDSESSION [...]

Not only the WM_QUERYENDSESSION !


This is the code that works fine for me:

void __fastcall TDiMainForm::WndProc( TMessage &Message )
{
switch ( Message.Msg )
{
// ... other messages ...

case WM_QUERYENDSESSION:
case WM_ENDSESSION:
YourCleanUpCodeHere();
break;

// ... other messages ...
}
TForm::WndProc( Msg );
}


--
Best regards,
Vladimir Stefanovic


 

{smallsort}

Re:Windows shutdown not closing my app

Quote
A question about your code, though. Do you really
want to do the cleanup in both the WM_QUERYENDSESSION
and the WM_ENDSESSION? Won't this result in
having your cleanup code execute twice?
OK. That was just a scratch to show that there are
*two* messages to look for...
Quote
>case WM_QUERYENDSESSION:
>case WM_ENDSESSION:
>YourCleanUpCodeHere();
>break;
In fact, all my cleanup code looks like this /pseudo/:
MyCleanUpCode()
{
if ( !Cleaned )
{
Cleaned = true;
Clean();
}
}
--
Best regards,
Vladimir Stefanovic
 

Re:Windows shutdown not closing my app

"Joseph F. Muscarella" < XXXX@XXXXX.COM >wrote in
message news: XXXX@XXXXX.COM ...
Quote
I only added the WM_QUERYENDSESSION message to the custom
component's
WndProc as a test to see if that might be the problem.
This message may not be received by all windows, since the first
window to reply with a zero will stop Windows from sending any more.
All windows will get a WM_ENDSESSION though.
--
Bruce
 

Re:Windows shutdown not closing my app

Does you app include any third party components that might be{*word*154} the
close process?
Mark
" Bruce Salzman" < XXXX@XXXXX.COM >wrote in message
Quote

"Joseph F. Muscarella" < XXXX@XXXXX.COM >wrote in
message news: XXXX@XXXXX.COM ...

>I only added the WM_QUERYENDSESSION message to the custom
>component's
>WndProc as a test to see if that might be the problem.

This message may not be received by all windows, since the first
window to reply with a zero will stop Windows from sending any more.
All windows will get a WM_ENDSESSION though.

--
Bruce


 

Re:Windows shutdown not closing my app

Quote
This message may not be received by all windows, since the first
window to reply with a zero will stop Windows from sending any more.
All windows will get a WM_ENDSESSION though.
I assume that the default behavior of a window without an OnCloseQuery
handler would be to set Result to 1 to allow the close to continue. Or do
I have to specifically have a message handler for the WM_QUERYENDSESSION in
*every* form in my program? I kind of doubt that because other apps I have
made do properly shut down when Windows goes down. I am assuming that
there is something funny about this one particular app.
By the way, this app has three forms that implement an OnCloseQuery handler.
Only the main form's handler is being executed (I tested it with a log
file.)
What other components besides TForm would respond to a WM_QUERYENDSESSION
message? If I knew that, I might be able to look a little deeper.
Joe
 

Re:Windows shutdown not closing my app

"Mark Guerrieri" < XXXX@XXXXX.COM >wrote in message
Quote
Does you app include any third party components that might be{*word*154} the
close process?

No third party components at all. Just what came with Builder, and what I
have written myself. What Borland supplied VCL components beside TForm
would potentially stop the close process?
Joe
 

Re:Windows shutdown not closing my app

I found the problem. Despite what I said before about not using third
party controls (my aging memory is shot) I discovered that the app does in
fact use a TNMHTTP control. That was keeping my app from closing upon
Windows shutdown. Sorry about any confusion. Thanks to all for your
help.
Joe