qocarlos
asked on
How to reload a document
Hi,
How can I reopen a document file that is currently open in the application?
TIA,
Carlos
How can I reopen a document file that is currently open in the application?
TIA,
Carlos
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
Or do you mean that you want to open another window on that document?
Or do you mean something else?
..B ekiM
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
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.
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.
ASKER
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()->OpenDocumentF ile(pathna me);
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
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()->OpenDocumentF
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
My code is from an SDI app .. maybe in an MDI it would have that effect.
Anyway, glad it worked for you.
Anyway, glad it worked for you.
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
Otherwise, you'll leak memory and/or resources.
..B ekiM
ASKER
Thanks for the comment Mike. I think my DeleteContents() implementation works correctly.
regards,
Carlos
regards,
Carlos
ASKER