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
Solved

Doc View and File Open

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
either24  challenge 19 101
matchUp  challenge 6 69
Modbus - whats the maximum I can store in one register? 4 80
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 858
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.

838 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