Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to reload a modified CDocument

How to reload a modified CDocument

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    luedi
    wrote on last edited by
    #1

    Hi, in a SDI application I want to reload a document that was modified with CDosument::SetModified (TRUE) by clicking on the document in the MRU list. But the framework will recognize the document as already beeing loaded and only activates it as current active document again. There seems to be also no simple method to override to allow such a behavoir. Two functions are involved in this: CDocManager::OpenDocumentFile and CDocTemplate::MatchDocType Both are virtual but both are also non trivial. This function does not belong into the CDocTemplate, since I would like to have it for all Documents in a MDI Application. But this function isn't trivial at all. Finally I have CWinApp::OnOpenRecentFile. But this isn't a real option also. Is there any simple way to do this? Thanks Dirk

    A 1 Reply Last reply
    0
    • L luedi

      Hi, in a SDI application I want to reload a document that was modified with CDosument::SetModified (TRUE) by clicking on the document in the MRU list. But the framework will recognize the document as already beeing loaded and only activates it as current active document again. There seems to be also no simple method to override to allow such a behavoir. Two functions are involved in this: CDocManager::OpenDocumentFile and CDocTemplate::MatchDocType Both are virtual but both are also non trivial. This function does not belong into the CDocTemplate, since I would like to have it for all Documents in a MDI Application. But this function isn't trivial at all. Finally I have CWinApp::OnOpenRecentFile. But this isn't a real option also. Is there any simple way to do this? Thanks Dirk

      A Offline
      A Offline
      Alvaro Mendez
      wrote on last edited by
      #2

      I took a look at your problem, and it seems like there's no simple way to do this. You need to derive from the DocManager class being used -- it's probably CFileDialogDocManager but look in your InitInstanstance for the exact name. Then you can override the OpenDocumentFile and pretty much copy the whole thing from the base class, except the part that checks the file's name. Well, you actually do want to check the file name so you can close the existing document. It's not bad, just not very pretty. BTW, don't forget to change InitInstance. Regards, Alvaro


      There are no stupid questions, but there are a lot of inquisitive idiots. -- despair.com

      L 1 Reply Last reply
      0
      • A Alvaro Mendez

        I took a look at your problem, and it seems like there's no simple way to do this. You need to derive from the DocManager class being used -- it's probably CFileDialogDocManager but look in your InitInstanstance for the exact name. Then you can override the OpenDocumentFile and pretty much copy the whole thing from the base class, except the part that checks the file's name. Well, you actually do want to check the file name so you can close the existing document. It's not bad, just not very pretty. BTW, don't forget to change InitInstance. Regards, Alvaro


        There are no stupid questions, but there are a lot of inquisitive idiots. -- despair.com

        L Offline
        L Offline
        luedi
        wrote on last edited by
        #3

        Thanks Alvaro, I hoped there was a simpler solution. Perhaps only setting a flag or something ;-) I realized it now, not overriding the OpenDocumentFile member function, but the MatchDocType function. This results in a much cleaner solution, since I don't have to copy code from the CSingleDocTemplate implementation :-) class CSingleReloadDocTemplate : public CSingleDocTemplate { DECLARE_DYNAMIC(CSingleReloadDocTemplate) public: CSingleReloadDocTemplate(UINT nIDResource, CRuntimeClass* pDocClass, CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass) : CSingleDocTemplate (nIDResource, pDocClass, pFrameClass, pViewClass) { } virtual Confidence MatchDocType(LPCTSTR lpszPathName, CDocument*& rpDocMatch) { Confidence confidence = CSingleDocTemplate::MatchDocType (lpszPathName, rpDocMatch); if (yesAlreadyOpen == confidence && rpDocMatch->IsModified()) { int answer = AfxMessageBox ("Do you want to reload the document", MB_YESNO); if (answer == IDYES) { // set the document modification state to "not modified" so the document template // will not complain during OpenDocumentFile () rpDocMatch->SetModifiedFlag(FALSE); // tell the DocumentManager, that no document with this title is already opened rpDocMatch = NULL; confidence = yesAttemptNative; } } return confidence; } }; IMPLEMENT_DYNAMIC (CSingleReloadDocTemplate, CSingleDocTemplate); For a MultiDocTemplate one should perhaps close the found document in some way (perhaps via CDocument::OnCloseDocument) since the CMultiDocTemplate::OpenDocumentFile() function will not reuse an existing open document like the CSingleDocTemplate. I'm not sure wether there is a combined method for this task that can be used for a SingleDocTemplate and a MultiDocTemplate (perhaps one can use CDocument::OnCloseDocument() already) Regards, Dirk

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups