Solved

Doc View and File Open

Posted on 1998-03-14
3
169 Views
Last Modified: 2013-11-19
When using the Doc/View archeatecture in MFC, if you try to open a document that is already open, the CDocument::OnOpenDocument doesn't get called. It doesn't do anything. I would like some sort of notification so I can reinitialize some things when the user tries to re-open a document.
0
Comment
Question by:EddK
  • 2
3 Comments
 
LVL 11

Expert Comment

by:mikeblas
ID: 1316988
Do you mean a document that's already opened by your application, or a document that's got its file locked because it's already opened by some other process?

.B ekiM
0
 

Author Comment

by:EddK
ID: 1316989
The document is already opened by my application. When I try to open it again, I want it to get reopened (Revert to saved)
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 20 total points
ID: 1316990
I'll assume that you're writing an MDI app. (Your question doesn't make much sense for an SDI app.)

You should derive your own class from CMultiDocTemplate and override MatchDocType() in that class:

Confidence CYourTemplate::MatchDocType(LPCTSTR lpszPathName, CDocument*& rpDocMatch)
{
   Confidence conf = CMultiDocTemplate::MatchDocType(lpszPathName, rpDocMatch);

   if (conf == CDocTemplate::yesAlreadyOpen)
   {
      // you know it's already open.
      // lpszPathName points to the fully qualified name
      // rpDocMatch points to the document that's already opened
      // after this function returns, MFC will set focus to the document's view
   }
}

If your application's InitInstance(), you need to make sure you hook up an instance of your newly derived class instead of a plain CMultiDocTemplate.

.B ekiM

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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