MFC Document changed
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: MFC Document changed

Hybrid View

  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
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    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.
             // ...
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    My latest articles:

  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

This is a survey!

HTML5 Development Center