Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MultiDocTemplate, single window

Posted on 1999-06-24
4
Medium Priority
?
255 Views
Last Modified: 2012-05-04
I am using MultiDocTemplate. When I open a new document (child window), how can I make the program to close the old one automatically? I only need one or no child window on the screen anytime.
Don't suggest me to use SingleDocTemplate,please.
0
Comment
Question by:JHuang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
naveenkohli earned 200 total points
ID: 1198402
In OnNewDocument function of your doc class, get the pointer to current active document. If its not NULL and is valid, then close it first and then continue on with opeing of new one.

CMyDoc::OnNewDocument ()
{
CWnd *pWnd = AfxGetMainWnd ();
CFrameWnd *pFrame = static_cast<CFrameWnd *>(pWnd);
CFrameWnd *pActiveFrameWnd = pFrame->GetActiveFrame ();

CDoucment *pDoc = pActiveFrameWnd->GetActiveDocument ();

if (pDoc != NULL) {
pDoc->SaveModified ();
pDoc->OnCloseDocument ();
}
}
0
 

Author Comment

by:JHuang
ID: 1198403
Yes, you are right.
I tested. It works fine.

You have earned 50 points already.

The following is an extera question:

How to close an old child frame when opening a new frame?

I put       
ON_COMMAND(ID_FILE_NEW, OnFileNew)
in CMainFrame,
CMainFrame::OnFileNew will creat a new frame.

When I press File & New, it will open a new window, too.
This time it's a Frame, not a Document, isn't it?

At this time, you answer won't work.

In any case, please tell me the result.


0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 1198404
The way this message works is that when you open a new file, the call has to go through OnNewDcoument. Thats why i suggested to put that close call in OnNewDocument. Try it, you should not have any probelm in closing the frame.

Good Luck!
0
 

Author Comment

by:JHuang
ID: 1198405
Thank you!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question