🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: WM_CLOSE / YesNo Dialog on closing program.

#7700
From: Remy Lebeau (TeamB)
Date: Mon, 10 Jan 2005 18:33
38 lines
2179 bytes
"Sinead Bunyan" <nospamSBUNYAN@DAIRYMASTER.COM> wrote in message
news:41e2a036@newsgroups.borland.com...

> I would like to know what is the best way of asking the user for a
> YES/NO dialog when closing a program by clicking with the mouse
> on the X

Use the form's OnCloseQuery event for that.  Set the CanClose parameter
accordingly.

> but this should not be required if windows is shutting down or doing a
restart.

For that, you need to intercept the WM_QUERYENDSESSION message as well.  The
best place to do that is to override the form's WndProc() method, ie:

    bool ShuttingDown = false;

    void __fastcall TForm1::WndProc(TMessage &Message)
    {
        if( Message.Msg == WM_QUERYENDSESSION )
            ShuttingDown = true;
        TForm::WndProc(Message);
    }

    void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
    {
        if( !ShuttingDown )
        {
            if( MessageDlg("Are you sure you would like to exit?",
mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrNo )
                CanClose = false;
        }
    }


Gambit
Technical Details
Message-ID: <41e2c9ff$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!spool-3.news.visi.com!news.tele.dk!news.tele.dk!small.news.tele.dk!lnewsoutpeer01.lnd.ops.eu.uu.net!lnewsinpeer00.lnd.ops.eu.uu.net!emea.uu.net!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <41e2a036@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,d947b84c7cfca26c
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <41e2a036@newsgroups.borland.com>
Subject: Re: WM_CLOSE / YesNo Dialog on closing program.
Date: Mon, 10 Jan 2005 10:33:12 -0800
Lines: 40
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: 68.69.17.41
Message-ID: <41e2c9ff$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1105381887 68.69.17.41 (10 Jan 2005 10:31:27 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!spool-3.news.visi.com!news.tele.dk!news.tele.dk!small.news.tele.dk!lnewsoutpeer01.lnd.ops.eu.uu.net!lnewsinpeer00.lnd.ops.eu.uu.net!emea.uu.net!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail