Solved

Doc View and File Open

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

707 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