Mainframe Close & WM_QUIT 
Author Message
 Mainframe Close & WM_QUIT

Hi,

I would like to prevent the clicking of the X at the top right of the
mainframe or at least catch it BEFORE any windows are destroyed.
Does anyone know how to do this, I can't find any info on this anywhere. If
you trap WM_QUIT - its too late the window's gone!
Alex.



Wed, 14 Nov 2001 03:00:00 GMT  
 Mainframe Close & WM_QUIT

Quote:
>I would like to prevent the clicking of the X at the top right of the
>mainframe or at least catch it BEFORE any windows are destroyed.

Handle WM_SYSCOMMAND and look for SC_CLOSE

Bob Moore [MVP]
http://www.mooremvp.freeserve.co.uk
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Due to an unreasonable amount of queries, I no
longer answer unsolicited email questions. Sorry,
no exceptions.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Wed, 14 Nov 2001 03:00:00 GMT  
 Mainframe Close & WM_QUIT


Quote:
>Hi,

>I would like to prevent the clicking of the X at the top right of the
>mainframe or at least catch it BEFORE any windows are destroyed.
>Does anyone know how to do this, I can't find any info on this anywhere. If
>you trap WM_QUIT - its too late the window's gone!
>Alex.

You want a handler like this:

afx_msg void CMyMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
   if (nID == SC_CLOSE) {
      if (IDontWantToLetTheUserCloseMeRightNow()) {
         return;
      }
   }
   CMainFrame::OnSysCommand(nID, lParam);

Quote:
}

    Use this technique if you want to display an "Are you sure?" warning
before closing the app, or if there are certain times or circumstances where
the app shouldn't be closed.  (And if you're refusing to close because
something special is going on, you should display a dialog explaining to the
user exactly what that special something is, and exactly what the user needs
to do to allow the closure to occur.)
    If you _never_ want to let the user close the app, then this is bad UI;
you're presenting a command as if it were available (the "X" in the caption
bar, and the "Close" command in the control menu), when you know it will
never be.  To fix this, in addition to the handler above, you should add this
code to your app's initialization code:

CMenu * pSysMenu = AfxGetMainWnd()->GetSystemMenu();
if (pSysMenu) {
    VERIFY(pSysMenu->DeleteMenu(SC_CLOSE,MF_BYCOMMAND));

Quote:
}

     Also, if your app doesn't always allow the Close command, you should
add handlers to your mainframe class for the WM_QUERYENDSESSION and
WM_ENDSESSION messages.  If you get a WM_QUERYENDSESSION message, the user
has just chosen to shut down or restart Windows, which will involve killing
your app. :)  If you decide to allow the shutdown, your OnQueryEndSession
handler should return TRUE.  If you decide to deny it, your handler should
return FALSE.

--
\o\ If you're interested in books and stories with transformation themes, \o\
/o/ please have a look at <URL:http://www.halcyon.com/phaedrus>. Thanks!  /o/
\o\   FC1.21:FC(W/C)p6arw A- C->++ D>++ H+ M>+ P R T++++ W** Z+ Sm RLCT   \o\
/o/              a cmn++++$ d e++ f+++ h- i++wf p-- sm#                   /o/



Fri, 16 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. application error when close the MainFrame window

2. MainFrame without Close

3. Dialog Open while MainFrame closed?

4. Cannot forward command messages to mainframe from controlbar after last user-created view is closed

5. C & IBM mainframes (Was: Re: Character Sets)

6. Static Function & MainFrame

7. MainFrame& icon

8. Saving/restoring mainframe & view positions/sizes

9. Mainframe caption & resizing

10. Static Function & MainFrame

11. can't accept WM_QUIT message

12. WM_QUIT

 

 
Powered by phpBB® Forum Software