Solved

Doc View and File Open

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASCII Non-Printable characters/codes and their HTML equivalents 6 158
Hibernate methods 2 87
has22 challenge 11 108
lucky13 challenge 11 164
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: 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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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