Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to programmatically close a document in a MDI app ?

784 views
Skip to first unread message

Gabriel Zerbib

unread,
Apr 18, 1999, 3:00:00 AM4/18/99
to
How can I force a document to close itself, without using the Close menu
command ?

Thanks.
Gabriel.

Thomas J. Mullen

unread,
Apr 18, 1999, 3:00:00 AM4/18/99
to

Get the document, and call OnCloseDocument(). If you have the frame or
the view, you can get the document very easily.

T.J. Mullen
OLDI Software

Eugene Kain

unread,
Apr 19, 1999, 3:00:00 AM4/19/99
to
Hello,

You can simulate what happens when the user selects the "File, Close" menu
command using this line of code:

AfxGetMainWnd()->PostMessage( WM_COMMAND, ID_FILE_CLOSE );

This will close the currently "active" document.
If you want to close a specific document, use code like this:

CYourDoc* pDoc;
// make pDoc point to the document you want to close
pDoc->OnCloseDocument();

You will find additional details in FAQ 2.12 of "The MFC Answer Book": How
do I programmatically close a document? You can find screen shots and a
sample program at
<http://www.mfcfaq.com/mfc_answer_book/contents/faq02-12.htm>.

Find more than 130 similar and advanced tips and techniques in "The MFC
Answer Book: Solutions for Effective Visual C++ Applications". For
additional details, surf to <http://www.mfcfaq.com>.

Good luck!

- Eugene Kain
Author of "The MFC Answer Book: Solutions for Effective Visual C++
Applications" (Addison-Wesley, 1998).
Visit the book's web site at <http://www.mfcfaq.com>
Get the best prices at
<http://www.amazon.com/exec/obidos/ASIN/0201185377/mfcfaqcom>


Gabriel Zerbib wrote in message <371A2114...@usa.net>...

vinodkumar

unread,
Apr 23, 1999, 3:00:00 AM4/23/99
to
Hi!
Get the Pointer to the required document and use doc->OnCloseDOcument()

Regards:
vinod kumar k.l

Gabriel Zerbib <gabriel...@usa.net> wrote in message
news:371A2114...@usa.net...

captainh...@gmail.com

unread,
Apr 15, 2018, 6:30:41 PM4/15/18
to
How to prevent the main application from closing when I close the last document?
0 new messages