Board index » cppbuilder » Problems when Windows Shuting down

Problems when Windows Shuting down


2005-11-04 12:18:10 AM
cppbuilder90
Hi, The mainform of my application cannot be closed because I use the
TTray and I only want my application to be shutdown when I right click
on the tray icon.
So I overided the OnCloseQuery.
But now When Windows shutsdown, I trap the message and it works.
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_ENDSESSION, TWMEndSession, WMEndSession)
END_MESSAGE_MAP(TForm)
But the problem is still there because the OnCloseQuery is called before
the WMEndSession. Because of that I cannot change the result of the
Onclose Query from the WMEndSession function.
Is there a way to work around this?
I also noticed that the line
TForm::WMEndSession(Message); in the example does not compile. Is there
a property that I need to put public in TForm?
thank you
Simon
 
 

Re:Problems when Windows Shuting down

"Simon Guertin" < XXXX@XXXXX.COM >wrote in message
Quote
So I overided the OnCloseQuery.
What does your OnCloseQuery event code look like? Are you taking the
Application->Terminated property into account?
Quote
But the problem is still there because the OnCloseQuery is called
before the WMEndSession. Because of that I cannot change the
result of the Onclose Query from the WMEndSession function.
TApplication already catches the WM_ENDSESSION message to set the
Application->Terminated property to true.
Quote
I also noticed that the line
TForm::WMEndSession(Message); in the example does not compile.
The example does not call TForm::WMEndSession(). It calls the
WMEndSession() method of your own class. The only method that is called
from TForm is Dispatch().
Quote
Is there a property that I need to put public in TForm?
Did you declare a WMEndSession() method in your class?
Gambit
 

Re:Problems when Windows Shuting down

Remy Lebeau (TeamB) wrote:
Quote
"Simon Guertin" < XXXX@XXXXX.COM >wrote in message
news:436a3877$ XXXX@XXXXX.COM ...


>So I overided the OnCloseQuery.


What does your OnCloseQuery event code look like? Are you taking the
Application->Terminated property into account?


>But the problem is still there because the OnCloseQuery is called
>before the WMEndSession. Because of that I cannot change the
>result of the Onclose Query from the WMEndSession function.


TApplication already catches the WM_ENDSESSION message to set the
Application->Terminated property to true.


>I also noticed that the line
>TForm::WMEndSession(Message); in the example does not compile.


The example does not call TForm::WMEndSession(). It calls the
WMEndSession() method of your own class. The only method that is called
from TForm is Dispatch().


>Is there a property that I need to put public in TForm?


Did you declare a WMEndSession() method in your class?


Gambit


I have found a solution, I have added the message map from windows
MESSAGE_HANDLER(
WM_QUERYENDSESSION, TWMQueryEndSession, QueryEndSession)
This message is sent first(WM_QUERYENDSESSION), I then prepare a boolean
that tells me windows is shuting down, then I make OnCloseQuery return
the right value.
finally I then do some processing in WMEndSession.
 

{smallsort}