Solved

Doc View and File Open

Posted on 1998-03-14
3
168 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now