Board index » cppbuilder » Problems with WM_QUERYENDSESSION

Problems with WM_QUERYENDSESSION

Quote
> What exactly are you trying to accomplish with this?
> Gambit

Hallo Remy!

I need a component wich manages the termination of my application. I'm lazy.
I don't want to write my code into the event handlers of my mainform. I want
to place only one component on my form.
All should be in that component.

I want to differ between termination by user (-> user needs the right to
terminate) and termination by Windows shutdown (-> always allowed).

In the WM_QUERYENDSESSION-handler I set a bool var "SysCloseQuery" to true
and give
Windows an Ok to terminate. In the OnCloseQuery-handler I check the
SysCloseQuery-var and the userlevel:

void __fastcall TMyClose::FormCloseQuery(TObject *Sender, bool &CanClose)
{
 CanClose = SysCloseQuery || (UserLevel > 9000);

Quote
}

And the component should be unvisible (derived from TComponent), but also be
able to answer to messages. Therefore I use WndProc of the parent form.

Rob'

 

Re:Problems with WM_QUERYENDSESSION


Quote
"Robby Gebauer" <robby.geba...@gmx.de> wrote in message

news:3d559222_1@dnews...

Quote
> In the WM_QUERYENDSESSION-handler I set a bool
> var "SysCloseQuery" to true and give Windows an Ok to
> terminate. In the OnCloseQuery-handler I check the
> SysCloseQuery-var and the userlevel:

Rather then doing that, you could just call Application->Terminate() when
appropriate, and then test for Application->Terminated in the OnCloseQuery
event:

    void __fastcall TMyClose::NewWndProc(TMessage &msg)
    {
        if(msg.Msg == WM_QUERYENDSESSION)
            Application->Terminate();
        FOrgWndProc(msg);
    }

    void __fastcall TMyClose::FormCloseQuery(TObject *Sender, bool
&CanClose)
    {
        CanClose = ( (Application->Terminated) || (UserLevel > 9000) );
    }

Quote
> And the component should be unvisible (derived from TComponent), but also
be
> able to answer to messages. Therefore I use WndProc of the parent form.

You could always assign just assign an event handler to the
TApplication::OnMessage event instead, rather than subclass the owner form.

Gambit

Re:Problems with WM_QUERYENDSESSION


Thank you Remy, I found the reason: It was a lacking call to DefWndProc in
another component. Now everything works well.

Rob'

Other Threads