🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
4 messages
4 total messages Started by Paul Thu, 22 Nov 2007 06:04
How to Ignore WM_QUERYENDSESSION
#961
Author: Paul
Date: Thu, 22 Nov 2007 06:04
50 lines
2539 bytes
Hi 

I am trying to use the SRVANY utility provided by Microsoft. The
documentation states the following

<quote>
This file describes the SRVANY.EXE utility. This utility allows running
Windows NT� applications as services. The benefits include:
- allow apps to survive logoff/logon sequences, hence saving the
overhead of re-starting them for each new user
- allow server apps to come-up and service requests even when no user
is logged-on
- allow apps to run and perform a task in a specific logon account,
different from the currently logged-on user

NOTICES:
1. Some applications may terminate upon logoff, even though they were
started as a service, if they don't ignore the WM_ENDSESSION message
(or CTRL_LOGOFF_EVENT). See "Programming Considerations" below for more
details.
</quote>

and the Programming Considerations section says
<quote>
For WIN32 graphical applications: when the currently logged-in user is
logging-off, all WIN32 top-level windows receive WM_QUERYENDSESSION and
WM_ENDSESSION messages. Some WIN32 applications choose to terminate
upon receipt of such messages. In order for your WIN32 application to
survive logoff, it must not do that: instead, your windows procedure
should call the default windows procedure on these messages.
</quote>

I have tried using the BEGIN_MESSAGE_MAP and overing the WndProc
approach. Unless Message.Result is set to true when handling the
WM_QUERYENDSESSION message the session log off is terminated as
expected from the MS Documentation.

What I am missing is how to **ignore** this message and **call the
default windows procedure on these messages**

Any advice appreciated

thanks
paul





-- 
Re: How to Ignore WM_QUERYENDSESSION
#964
Author: Asger Joergensen
Date: Thu, 22 Nov 2007 11:24
27 lines
1474 bytes
Hi Paul 
 
 Paul says:
> Hi 
> 
> I have tried using the BEGIN_MESSAGE_MAP and overing the WndProc
> approach. Unless Message.Result is set to true when handling the
> WM_QUERYENDSESSION message the session log off is terminated as
> expected from the MS Documentation.
> 
> What I am missing is how to **ignore** this message

I think this means that if You have this line: 

TSomething::Dispatch((void*)&Msg);

in Your message map do this:

//TSomething::Dispatch((void*)&Msg);
 
> and **call the default windows procedure on these messages**

I dont know about this part

Kind regards
Asger
Re: How to Ignore WM_QUERYENDSESSION
#971
Author: Remy Lebeau (TeamB)
Date: Thu, 22 Nov 2007 20:47
54 lines
2249 bytes
"Paul" <paulm@xacom.com.au> wrote in message
news:474529f6@newsgroups.borland.com...

> I have tried using the BEGIN_MESSAGE_MAP and overing
> the WndProc approach.

That won't work by itself.  All that allows you to do is hook the messages
at the TForm level, but the messages are also handled at the TApplication
level as well.  You need to use TApplication::HookMainWindow() as well.  For
example:

    class TForm1 : public TForm
    {
    protected:
        virtual void __fastcall WndProc(TMessage &Message);
    };

    __fastcall TForm1::TForm1(TComponent *Owner)
        : TForm(Owner)
    {
        Application->HookMainWindow(&AppHook);
    }

    __fastcall TForm1::~TForm1()
    {
        Application->UnhookMainWindow(&AppHook);
    }

    void __fastcall TForm1::WndProc(TMessage &Message)
    {
        if( Message.Msg == WM_QUERYENDSESSION )
        {
            // ignore it
            Message.Result = DefWindowProc(Handle, Message.Msg,
Message.WParam, Message.LParam);
        }
        else
            TForm::WndProc(Message);
    }

    bool __fastcall TForm1::AppHook(TMessage &Message)
    {
        if( Message.Msg == WM_ENDSESSION )
        {
            Message.Result = DefWindowProc(Application->Handle, Message.Msg,
Message.WParam, Message.LParam);
            return true;
        }
        return false;
    }


Gambit
Re: How to Ignore WM_QUERYENDSESSION
#976
Author: Paul
Date: Thu, 22 Nov 2007 21:56
15 lines
1253 bytes
Remy Lebeau (TeamB) wrote:

> 
> 
> That won't work by itself.  All that allows you to do is hook the
> messages at the TForm level, but the messages are also handled at the
> TApplication level as well.  You need to use
> TApplication::HookMainWindow() as well.  For example:


Thanks a lot for that code - as soon as I saw the DefWindowProc the
penny dropped. Many thanks for your help - much appreciated

cheers
Paul
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads