WM_QUERYENDSESSION problem on C++ Builder 2010
-
I have the following code: .... private: void __fastcall WMQueryEndSession(TWMQueryEndSession& Message); BEGIN_MESSAGE_MAP MESSAGE_HANDLER(WM_QUERYENDSESSION, TWMQueryEndSession, WMQueryEndSession) END_MESSAGE_MAP(TForm) ..... void __fastcall TForm1::WMQueryEndSession(TWMQueryEndSession & Message) { Message.Result=0; } Compiled by C++ Builder 2010, the code works improperly. Although it prevents the computer from shut down, but it also closes my application. The code below fixes the problem, but it is not stable (sometimes does not work) and the such long delay in 10 seconds is not acceptable in my case: void __fastcall TForm1::WMQueryEndSession(TWMQueryEndSession& Message) { Sleep(10000); Message.Result=0; } Does enybody know how to fix the problem? Thanks.
-
I have the following code: .... private: void __fastcall WMQueryEndSession(TWMQueryEndSession& Message); BEGIN_MESSAGE_MAP MESSAGE_HANDLER(WM_QUERYENDSESSION, TWMQueryEndSession, WMQueryEndSession) END_MESSAGE_MAP(TForm) ..... void __fastcall TForm1::WMQueryEndSession(TWMQueryEndSession & Message) { Message.Result=0; } Compiled by C++ Builder 2010, the code works improperly. Although it prevents the computer from shut down, but it also closes my application. The code below fixes the problem, but it is not stable (sometimes does not work) and the such long delay in 10 seconds is not acceptable in my case: void __fastcall TForm1::WMQueryEndSession(TWMQueryEndSession& Message) { Sleep(10000); Message.Result=0; } Does enybody know how to fix the problem? Thanks.
-
I had a simular problem and had to check for 2 messages WM_ENDSESSION or WM_QUERYENDSESSION. Then set a flag to indicate shutdown, this flag was then used in an OnClosing event that by default cancelled the close to minimize to the system tray
ARopo wrote:
I had a simular problem and had to check for 2 messages WM_ENDSESSION or WM_QUERYENDSESSION. Then set a flag to indicate shutdown, this flag was then used in an OnClosing event that by default cancelled the close to minimize to the system tray
Thank you for your answer. Hovewer your suggestion will not work in my case as WM_ENDSESSION is calling Application->Termiante() which terminates program even if the flag in OnClose event is set to hide or none and the application is minimized to the systray. Calling Application->Termiante() by WM_ENDSESSION (even if application returns zero to WM_QUERYENDSESSION message) is recent bug of C++ Builder 2010. Previous versions of the compiler worked properly and did not call Application->Termiante() if application returned zero to WM_QUERYENDSESSION message. Does anybody know how to fix or bypass this bug of the C++ Builder 2010?