CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2010

    MFC Document changed

    Hi everyone,
    I created a MFC MDI Application. I want to manage it in order to check, every time a View get focus, that its Document has been changed or not (for example using another hinstance of the same application or a text editor), notifying with a MessageBox something like this "(file name): this file has been modified by another program, do you want to reload it?".
    How can I manage this behaviour?

    Thanks a lot for your help.

  2. #2
    Join Date
    Feb 2003
    Iasi - Romania

    Re: MFC Document changed

    You can handle WM_MDIACTIVATE message and get the last modified time of the document's file.
    void CChildFrame::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd) 
       CMDIChildWnd::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd);
          CDocument* pDoc = ((CFrameWnd*)pActivateWnd)->GetActiveDocument();
          const CString& strFile = pDoc->GetPathName();
             CFileStatus fileStatus;
             VERIFY(CFile::GetStatus(strFile, fileStatus));
             CTime m_TimeModified = fileStatus.m_mtime;
             // Next, compare the actual modified time with last modified time,
             // which may be one previously stored in document's class.
             // ...
    "When in Rome, do as Romans do."
    My latest articles: http://codexpert.ro/blog/author/ovidiu-cucu/

  3. #3
    Join Date
    Sep 2010

    Re: MFC Document changed

    It works, except that this update is not on application focus, but on Document switching. Anyway, I put this code in CMainFrame::OnActivateApp and it works perfectly!
    Thanks a lot.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.