🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #971

Re: How to Ignore WM_QUERYENDSESSION

#971
From: 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
Technical Details
Message-ID: <4745eaa1$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <474529f6@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,82d0c9e28c8f059
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <474529f6@newsgroups.borland.com>
Subject: Re: How to Ignore WM_QUERYENDSESSION
Date: Thu, 22 Nov 2007 12:47:20 -0800
Lines: 56
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 75.83.29.61
Message-ID: <4745eaa1$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1195764385 75.83.29.61 (22 Nov 2007 12:46:25 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail