Solved

How to reload a document

Posted on 2000-05-18
9
206 Views
Last Modified: 2013-11-20
Hi,

How can I reopen a document file that is currently open in the application?

TIA,
Carlos
0
Comment
Question by:qocarlos
  • 4
  • 3
  • 2
9 Comments
 
LVL 3

Author Comment

by:qocarlos
ID: 2822686
Adjusted points from 100 to 150
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2823068
What do you mean by "reopen"?  Do you want to close the open document, then reload it immediately from storage?

Or do you mean that you want to open another window on that document?

Or do you mean something else?

..B ekiM
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 150 total points
ID: 2824036
I assume you want a 'revert' option that re-loads the document from disk.

here is what I do...

void CMyDoc::OnFileRevert() {
  CString pathname = GetPathName();
  OnNewDocument();
  AfxGetApp()->OpenDocumentFile(pathname);
}

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:qocarlos
ID: 2825039
Hi,
Thanks for the answer.
What I need to do is that if I user wants to open a currently opened document, I want the application to close the document and open it again from the disk.
The problem is that if OpenDocumentFile() finds that the file is already currently opened, OpenDocumentFile() activates the view for that file and then returns. It does not re-open the file.
How can I change this behavior so the file can be re-opened?

Thanks
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2825347
That is what my answer does.

Add a 'Revert' option to the file menu, and make OnFileRevert the handler for it.

The behaviour of Open not reloading a document is standard windows behaviour .. you should not change that, as it will confuse users familiar with windows.  A 'revert' (or 'reload') command is quite common when you want to reload a file from disk.

0
 
LVL 3

Author Comment

by:qocarlos
ID: 2826132
Hi,
Thanks, sorry I had misunderstood your previous answer.
Now I think I gotit. The only problem is that your code leaves a blanck document opened.
I have just added a call to OnCloseDocument:
void CMyDoc::OnRevert()
{
      CString pathname = GetPathName();
      OnNewDocument();
      AfxGetApp()->OpenDocumentFile(pathname);
      OnCloseDocument();
      
}

and now it works. I hope I didn't make anything wrong, because in this application I have changed the standar MFC way to open a document.
Thanks again,
Carlos
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2826139
My code is from an SDI app .. maybe in an MDI it would have that effect.

Anyway, glad it worked for you.
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2827919
This is the right way to do it--but if you're using this technique (especially in an MDI app), it's imperative that you have a correct DeleteContents() implemntation. That function will be called by the framework to clear the document. You should use that routine to free, close, or erase anything that the document might reload or recrate as it is set up again.

Otherwise, you'll leak memory and/or resources.

..B ekiM
0
 
LVL 3

Author Comment

by:qocarlos
ID: 2828861
Thanks for the comment Mike. I think my DeleteContents() implementation works correctly.

regards,
Carlos
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ODBC Connection Logging, ADO.NET 6 71
unable to delete all specified values regedit 38 731
iSeries DB2 Query 2 98
How do I get Window Title of all opened process? 4 40
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

696 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